all groups > asp.net webcontrols > october 2006 >
You're in the

asp.net webcontrols

group:

operations on string



operations on string mamin NO[at]SPAM o2.pl
10/30/2006 7:20:18 AM
asp.net webcontrols: Hi all,
Anyone know some smart way to get two first substrings from string, in
example how to get string
"aaaa bbbb" from string "aaaa bbbb cccc ddddddd"?
RE: operations on string Ananth Ramasamy Meenachi
10/31/2006 1:34:02 AM
Hi,

Please find the method below which will return string;

private string GetSecondSubstring(string str)
{
string[] Str;
char dlimit = ' ';

if (str.Length !=0)
{
Str = str.Split(dlimit);

if (Str.GetUpperBound(0) > 1)
str = Str[0] + dlimit + Str[1];

}
return str;
}


[quoted text, click to view]
Re: operations on string marss
10/31/2006 2:05:25 AM

mamin@o2.pl =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=B2:
[quoted text, click to view]


string str =3D "aaaa bbbb cccc ddddddd";
System.Text.RegularExpressions.Regex re =3D new
System.Text.RegularExpressions.Regex(@"^\w+\s+\w+\b");
System.Text.RegularExpressions.Match match =3D re.Match(str);
if (match.Success)
{
string res =3D match.Value;
//...........
}
Re: operations on string mamin NO[at]SPAM o2.pl
10/31/2006 5:12:02 AM
Thanks, it seems to be the best way.
AddThis Social Bookmark Button