Regular expression to split string and number

前端 未结 8 1910
天涯浪人
天涯浪人 2020-12-03 05:30

I have a string of the form:

codename123

Is there a regular expression that can be used with Regex.Split() to split the alphabetic part and

相关标签:
8条回答
  • 2020-12-03 06:03

    Another simpler way is

    string originalstring = "codename123";
    string alphabets = string.empty;
    string numbers = string.empty;
    
    foreach (char item in mainstring)
    {
       if (Char.IsLetter(item))
       alphabets += item;
       if (Char.IsNumber(item))
       numbers += item;
    }
    
    0 讨论(0)
  • 2020-12-03 06:08

    A little verbose, but

    Regex.Split( "codename123", @"(?<=[a-zA-Z])(?=\d)" );
    

    Can you be more specific about your requirements? Maybe a few other input examples.

    0 讨论(0)
提交回复
热议问题