Click here to Skip to main content
15,884,237 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,
i need to split the string.
for eg:
"q2px1tfi9jNvrX07uxH78DUCzuXZKlwZjtN3iruaMi0=" This is my string. now i need to split
q2px1-tfi9j- NvrX0-7uxH7-8DUCz. and the remaining strings are no need.
Posted
Updated 10-Jul-13 20:28pm
v2
Comments
sorawit amorn 4-Aug-13 14:01pm    
Do you have more specific requirements of splitting input string ?

1 solution

Hello,

You can do it using a regular expression as shown below.
C#
using System;
using System.Text.RegularExpressions;

class SplitStringTester {
    public string[] RegxSplit(string pattern, string input) {
        int i = 0;
        string[] arrRet = null;
        Regex rgx = new Regex(pattern, RegexOptions.IgnoreCase);
        MatchCollection matches = rgx.Matches(input);
        if (matches.Count > 0)
        {
            arrRet = new string[matches.Count];
            foreach(Match m in matches) {
                arrRet[i] = m.Value;
                i++;
            }
        }
        return arrRet;
    }

    public static void Main() {
        SplitStringTester tst = new SplitStringTester();
        string[] arrRet = tst.RegxSplit(@"(.{5})?", @"q2px1tfi9jNvrX07uxH78DUCzuXZKlwZjtN3iruaMi0=");
        if (arrRet != null) {
            Console.WriteLine("{0} ({1} matches):", @"q2px1tfi9jNvrX07uxH78DUCzuXZKlwZjtN3iruaMi0=", arrRet.Length);
            foreach (string sTok in arrRet)
                Console.WriteLine(sTok);
        }
        Console.ReadKey();
    }
}

Another way could be found here[^].

Regards,
 
Share this answer
 
v3
Comments
Orcun Iyigun 11-Jul-13 2:53am    
my 5+
Prasad Khandekar 11-Jul-13 3:07am    
Thank's a lot.

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