Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
How to separate character and number part from string?
ex:i have 4576rs
now i want to split 4567 rs


thanks and regards
Hari
Posted

Try this
C#
string subjectString = "4567rs";
          var splitArray = Regex.Split(subjectString, @"(?<=\d)(?=\p{L})|(?<=\p{L})(?=\d)");

           string number = splitArray[0];
           string str = splitArray[1];


Hope this helps
 
Share this answer
 
Comments
Hari Krishna Prasad Inakoti 7-Mar-13 0:41am    
Thanq Jameel Moideen
without using regular expression

C#
private void demo()
       {
           string cell = "4567rs";
           int row, a = getIndexofNumber(cell);
           string Numberpart = cell.Substring(a, cell.Length - a);
           row = Convert.ToInt32(Numberpart);
           string Stringpart = cell.Substring(0, a);
       }

       private int getIndexofNumber(string cell)
       {
           int indexofNum=-1;
           foreach (char c in cell)
           {
               indexofNum++;
               if (Char.IsDigit(c))
               {
                   return indexofNum;
               }
            }
           return indexofNum;
       }
 
Share this answer
 
v2

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