Skip to content

Instantly share code, notes, and snippets.

@norrs
Created October 26, 2010 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save norrs/646666 to your computer and use it in GitHub Desktop.
Save norrs/646666 to your computer and use it in GitHub Desktop.
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