There is a line with the sentence, for example "В неделе 7 дней" . How to divide a line by this figure into "В неделе " and " дней" if you have not previously known what figure it will be? I wanted to try using .Split() , but it is not clear what should be in brackets.

    3 answers 3

    The Split method also takes an array, each element of which cuts a line.

    if you only have numbers up to 10 in the text, you can do this:

     var input = "В неделе 7 дней"; var t1 = input.Split("0123456789".ToCharArray()); 

    if any numbers can come together, it’s better to use Regex:

     var input = "В неделе 7 дней"; var t2 = Regex.Split(input, "-?[0-9]+"); 

      It can be divided by the regular expression Regex.Split , where the second parameter can be passed to the regular.

      Here even an example is just for your question.

         var date = "В неделе 7 дней"; var firstDigitValue = date.FirstOrDefault(x => Char.IsDigit(x)); var lastDigitValue = date.LastOrDefault(x => Char.IsDigit(x)); var weekPart = date.Substring(0, firstDigitValue); var dayPart = date.Substring(lastDigitValue, date.Length); 

        I am sure that this is not the best result, but I think that this should work.