example...
printf("helloworld");
i want to get the helloworld from this statement. using any regular expression? or any option?
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
JureRank #2,128 · 670 reputationPosted Nov 4, 2010, 6:13 AM EDT
The easiest way is to split the text with quotation marks as separators, using string.Split method. strings at every odd index in the returned array (result[1], result[3], etc) is what's between the quotes. If array's length is odd, then all quotations are between two quotation marks, thus properly formatted. If array's length is even, last quotation hasn't been ended/escaped with quotation mark yet.
vishnu krishnan103 reputationPosted Nov 4, 2010, 7:50 AM EDT
string result= name.split( ? )
what will be the ( ? ) position
JureRank #2,128 · 670 reputationPosted Nov 4, 2010, 8:06 AM EDT
name.split('"'), since you're going to use quotation mark(") as separator.
If you need more options, check out StringSplitter.
vishnu krishnan103 reputationPosted Nov 4, 2010, 8:54 AM EDT
@"^('"')$";
this will give the error.
JureRank #2,128 · 670 reputationPosted Nov 4, 2010, 10:33 AM EDT
"[^"]*"
or
"(.*?)"
but it will keep quotation marks, so you'll still have to trim the resulting strings. Also, don't forget to escape the quotes by writing \" instead of just ".
So, in C# this would be:
MatchCollection mc = Regex.Matches(sample, "\"(.*?)\"");
foreach (Match m in mc)
{
Console.WriteLine(m.ToString().Trim('"'));
}
All this is completely different from what I suggested first (splitting), regex won't split strings, but return just text that's between quotes.
vishnu krishnan103 reputationPosted Nov 5, 2010, 11:01 PM EDT
i have change that like
if (Regex.IsMatch(sample, "\"(.*?)\""))
{
Console.WriteLine(sample.ToString().Trim('"'));
}
got it but one problem, if am giving sample like hello"world" it will not working?
vishnu krishnan103 reputationPosted Nov 5, 2010, 11:40 PM EDT