Click here to Skip to main content
15,887,854 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a
C#
string abc= "1) ABC <br> 2) SHJKL <br> 3) SJLKK JJJLHH";

i want result arr[0]= ABC, arr[1]= SHJKL, arr[2]= SJLKK JJJLHH. Means remove
C#
"<br>" and 1) 2) 3)
characters and get result of string in an array. counting upto 3 is not fixed. it may be more or less.
How to do it.
Thanx in advance
Posted

Use a Regex:
VB
public static Regex regex = new Regex(
      "(?<=\\d\\))([^\\<]+)(?=\\<[^\\>]+\\>)",
    RegexOptions.IgnoreCase
    | RegexOptions.CultureInvariant
    | RegexOptions.IgnorePatternWhitespace
    | RegexOptions.Compiled
    );

// Capture all Matches in the InputText
MatchCollection ms = regex.Matches(InputText);



Get a copy of Expresso [^] - it's free, and it examines and generates Regular expressions.
 
Share this answer
 
XML
This will give slow performance but still may help you
string abc = "1) ABC <br> 2) SHJKL <br> 3) SJLKK JJJLHH";
            List<string> arr=new List<string>();
            foreach (string s in abc.Substring(2).Split(')'))
            {
                arr.Add(s.Contains("<br>") == true ? s.Substring(0, s.Length - 6) : s);
            }
 
Share this answer
 
How about this Regex will replace all and give you a plain text later do what you want

string str = Regex.Replace("1) ABC <br> 2) SHJKL <br> 3) SJLKK JJJLHH", "[^(A-Z)]|[\\)]", string.Empty);
 
Share this answer
 
you can use Split method
check following link :
http://www.dotnetperls.com/split[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900