How can i remove just first comma + space from below if its there else do nothing.
string comments = ", 38, ";
How can i remove just first comma + space from below if its there else do nothing.
string comments = ", 38, ";
if( comments.StartsWith(", ") && comments.Length > 2 ) {
comments = comments.Substring(2);
}
The best way would be to use the String.TrimStart(...) method.
string comments = ", 38, ";
string commentsOK = "38, ";
string trimmedComments = comments.TrimStart(',', ' ');
string trimmedCommentsOK = commentsOK.TrimStart(',', ' ');
After this both trimmedComments and trimmedCommentsOK would have the value "38, ".
String.TrimStart method reference: http://msdn.microsoft.com/en-us/library/system.string.trimstart.aspx