Using LINQ to parse the numbers from a string

前端 未结 7 1476
忘掉有多难
忘掉有多难 2021-02-19 22:00

Is it possible to write a query where we get all those characters that could be parsed into int from any given string?

For example we have a string like: \"$%^DDFG

7条回答
  •  深忆病人
    2021-02-19 22:40

    > 'string strRawData="12#$%33fgrt$%$5"; 
    > string[] arr=Regex.Split(strRawData,"[^0-9]"); int a1 = 0; 
    > foreach (string value in arr) { Console.WriteLine("line no."+a1+" ="+value); a1++; }'
    
    Output:line no.0 =12
    line no.1 =
    line no.2 =
    line no.3 =33
    line no.4 =
    line no.5 =
    line no.6 =
    line no.7 =
    line no.8 =
    line no.9 =
    line no.10 =5
    Press any key to continue . . .
    

提交回复
热议问题