複数の空白(たとえば1 1 A)を持つwinformsテキストボックスでは、空白が1つある間に、文字列メソッドまたは正規表現を使ってこれをどのように検出できますか?この機能は、あなたのためのトリックを行う必要がありテキストボックス内の空白の検出
おかげ
複数の空白(たとえば1 1 A)を持つwinformsテキストボックスでは、空白が1つある間に、文字列メソッドまたは正規表現を使ってこれをどのように検出できますか?この機能は、あなたのためのトリックを行う必要がありテキストボックス内の空白の検出
おかげ
使用IndexOfの
if("1 1a".IndexOf(' ') >= 0) {
// there is a space.
}
。
bool DoesContainsWhitespace()
{
return textbox1.Text.Contains(" ");
}
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;
}
かなりはっきりしていない問題が何であるか、場合にあなただけ与えられた文字列内の任意の場所のホワイトスペース、その他によって提案されたものと異なる解決策があるかどう伝える方法をしたいが、 (も動作)スタックのユーザーは次のようになります場合は
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を参照してください。
あなたはただそれを検出するのか、それとも何かをしたいのですか? – diggingforfire
あなたがマッチさせようとしていることははっきりとは分かりません。あなたはもう少し詳しく説明できますか? – JaredPar