Skip to content

Instantly share code, notes, and snippets.

@norrs

norrs/gist:646666

Created Oct 26, 2010
Embed
What would you like to do?
package no.ntnu.tdt4237.helperactions;
public class StringHelpers {
public static String getBlogOwnerName(String url)
{
return urlToString(url).replaceFirst("http?://.*/blog/","");
}
public static String getProfileOwnerName(String url)
{
return urlToString(url).replaceFirst("http?://.*/profile/","");
}
public static String getPostOwnerName(String url, String basePath)
{
return urlToString(url).replaceFirst("http?://.*/"+basePath+"/","").replaceFirst("/[0-9]+[-][0-9]+[0-9]+[-][0-9]+/.*$", "");
}
public static String getPostOwnerName(String url)
{
return getPostOwnerName(url, "post");
}
public static String getPostTitle(String url, String ownerName, String basePath)
{
return urlToString(url).replaceFirst("http?://.*/"+basePath+"/"+ownerName+"/[0-9]+[-][0-9]+[0-9]+[-][0-9]+/","");
}
public static String getPostTitle(String url, String ownerName)
{
return getPostTitle(url, ownerName, "post");
}
public static String getPostDate(String url, String ownerName, String basePath)
{
return urlToString(url).replaceFirst("http?://.*/"+basePath+"/"+ownerName+"/","").replaceFirst("/.*$", "");
}
public static String getPostDate(String url, String ownerName)
{
return getPostDate(url, ownerName, "post");
}
public static String urlToString(String url) {
return url.replaceAll("%20", " ");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.