Split() function

Posted by Abhi_patil under ASP.NET on 2/15/2009 | Views : 13396 | Status : [Member] | Replies : 2
//i want to split with all these characters.
char[] arr ={ ' \n' , ' ' , ';' , '.' };

arrWords = strCompleteOriginal.Split(arr);

In this split function .It is not splitting with '\n'.
why?
i want get split with all these characters.
is there any other way?




Responses

Posted by: Poster on: 2/15/2009 [Member] Starter

Up
0
Down
May be because \n has a escape character (\) and more than one character (\n). Char only takes one character at a time.

Instead of doing this, you can replace '\n' with <br> using Replace function and after than split.

Thanks

Abhi_patil, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Majith on: 2/18/2009 [Member] Starter

Up
0
Down
Hi,

Normally the Replace Function doesnt consider special Characters
Ex :
public static string ReplaceSingleQuote(string value)
{
if (!string.IsNullOrEmpty(value))
{
return value.Replace("\n", "");
}
return value;
}

It dosen't remove \n

Solution :

return value.Replace(@"\n", "");

Add the @ symbol for repalcing Special Characters



Abhi_patil, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response