Detecting whitespace in textbox

后端 未结 4 1017
无人及你
无人及你 2021-01-16 23:01

In a WinForms textbox with multiple whitespaces (e.g. 1 1 A), where, between the 1s, there is whitespace, how could I detect this via the string methods or regex?

4条回答
  •  不知归路
    2021-01-16 23:47

    int NumberOfWhiteSpaceOccurances(string textFromTextBox){
     char[] textHolder = textFromTextBox.toCharArray();
     int numberOfWhiteSpaceOccurances = 0;
     for(int index= 0; index < textHolder.length; index++){
       if(textHolder[index] == ' ')numberOfWhiteSpaceOccurances++;
     }
     return numberOfWhiteSpaceOccurances;
    }
    

提交回复
热议问题