When I get the list value from the “Author” column on a list in SharePoint 2010, the following gets displayed:
2;#SP10Setup
Now the user that created that particular list item was “SP10Setup”, now is there a simple way to remove “2;#” at the beginning of SP10Setup without affecting the digits in “SP10Setup”?
I have a method that currently is stripping out all digits
//method to strip out unnecessary digits
public static string RemoveDigits(string key)
{
return Regex.Replace(key, @"\d", "");
}
this is how I get the particular list item value:
string author = listItem["Author"].ToString();
this is how I removed unwanted digits and characters:
//calling the RemoveCharacter method
string noDigitsAuthor = RemoveDigits(author);
string cleanedupAuthor = noDigitsAuthor.Replace(";", "").Replace("#", "");
The result I get from this is “SPSetup”, but ideally I would want the result to be “SP10Setup”.
What would be the quickest and easiest way to achieve this…
Thanks in Advance
You should not do it yourself.
Use SPFieldLookupValue class
so you will have: