How to split string by numbers in C#

1 Answer

0 votes
using System;
using System.Text.RegularExpressions;

public class MyClass
{
    public static void Main(string[] args)
    {
        string str = "java123c++45php090python";
        
        Regex regex = new Regex(@"\d+");
        string[] substrings = regex.Split(str);

        foreach (string word in substrings) {
            Console.WriteLine(word);
        }
    }
}



/*
run:
 
java
c++
php
python
 
*/

 



answered May 1, 2024 by avibootz

Related questions

1 answer 185 views
1 answer 79 views
2 answers 135 views
1 answer 100 views
100 views asked Jul 31, 2023 by avibootz
1 answer 147 views
147 views asked May 30, 2023 by avibootz
...