2012-01-15 3 views
0

여러 공백 (예 : 1 1 A)이있는 winforms 텍스트 상자에서 1 사이에 공백이있는 경우 어떻게 문자열 메소드 또는 정규식을 통해이를 감지 할 수 있습니까?텍스트 상자의 공백 감지

감사

+1

그냥 감지하고 싶습니까? – diggingforfire

+0

일치하는 부분이 정확히 명확하지 않습니다. 조금 더 explian 수 있을까요? – JaredPar

답변

0

이 기능은 당신을 위해 트릭을 할해야

if("1 1a".IndexOf(' ') >= 0) { 
    // there is a space. 
} 
0

사용 같이 IndexOf.

bool DoesContainsWhitespace() 
{ 
    return textbox1.Text.Contains(" "); 
} 
0
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; 
} 
0

꽤 명확하지 문제가 무엇인지, 경우에 당신은 주어진 문자열에 어디 공백, 다른 제안한 것과 다른 해결책이 있는지 알려줄 수있는 방법을 원하지만 (또한 작업) 스택 사용자는 다음의 경우에

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Text.RegularExpressions; 
using System.Threading.Tasks; 

namespace Testing 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      Console.WriteLine(PatternFound("1 1 a")); 
      Console.WriteLine(PatternFound("1  1 a")); 
      Console.WriteLine(PatternFound("   1  1 a")); 

     } 

     static bool PatternFound(string str) 
     { 
      Regex regEx = new Regex("\\s"); 
      Match match = regEx.Match(str); 
      return match.Success; 
     } 
    } 
} 

당신은 연속 된 공간의 주어진 연속 표시 여부를 결정하는 원하는, 당신은 정규식 패턴 문자열에 더 추가해야합니다. 옵션은 http://msdn.microsoft.com/en-us/library/az24scfc(v=vs.110).aspx을 참조하십시오.

관련 문제