Possible Duplicate:
How do I split a string by strings and include the delimiters using .NET?
I have following code:
string Test="abc * (xyz+ pqr) - 10/100";
char[] delimiters = new char[] { '+', '-', '*', '/', '(', ')' };
string[] parts = Test.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < parts.Length; i++)
{
Response.Write(parts[i]);
}
I m getting output as:
abc xyz pqr 10100
But i want:
abc
*
(
xyz
+
pqr
…and so on.
(in c# or in javascript)
In JavaScript, you can use capturing groups of a regex:
Yet this does not work in older Internet Explorers, you would need to do it manually there or use this shim. Better, cross-browser solution: Just match variable names and numbers as well, and use
match: