如何确定字符串中是否没有符号。 [英] How determinate if there no symbol in a string.
问题描述
我想确定字符串中是否没有符号?
例如
" 12ab34"," 123a5bc"," a123c4"没问题,但是23#45,2a,35不行。
因此,广告说...
I想确定字符串中是否没有符号?
例如
" 12ab34"," 123a5bc"," a123c4"没问题,但是23#45,2a,35不行。
您可能想要搜索正则表达式。希望有所帮助:-)
Flo
如何在此问题中使用正则表达式?
Flo'Irian''Schaetz" < ir *** @ gmx.de>
????????:45 ********************** *@newsspool1.arcor-online.net ...
因此,广告发言......
>我想确定字符串中是否没有符号?
例如
" 12ab34"," 123a5bc"," a123c4"没问题,但是23#45,2a,35不行。
您可能想要搜索正则表达式。希望有所帮助:-)
Flo
ad写道:
我想确定字符串中是否有符号?
例如
12ab34,123a5bc,a123c4,没问题,但是23#45,2a,35不行。
您可以使用正则表达式...
这里有一些代码演示了IsValidString()函数检查
你对琴弦的要求。
------------------------------- ----------------
使用System.Text.RegularExpressions;
private void button1_Click (对象发送者,EventArgs e)
{
CheckStrings();
}
静态private void CheckStrings()
{
StringBuilder sb = new StringBuilder();
string [] arr = new string []
{12ab34,123a5bc,a123c4,23#45,2a,35, };
foreach(字符串s in arr)
{
sb.Append(s);
sb .Append("是&);;
sb.Append(IsValidString(s)?" OK":not ok);
sb.Append (" \ n");
}
MessageBox.Show(sb.ToString());
}
静态私有bool IsValidString(字符串s)
{
正则表达式re =新正则表达式(" ^ [0-9a-zA-Z ] *
I want to determinate if there no symbol in a string?
for example
"12ab34", "123a5bc", "a123c4" is ok, but "23#45", 2a,35" is not ok.
And thus, ad spoke...
I want to determinate if there no symbol in a string?
for example
"12ab34", "123a5bc", "a123c4" is ok, but "23#45", 2a,35" is not ok.You probably want to search for "Regular Expressions". Hope that helps :-)
Flo
How can I use Regular Expressions with this question?
"Flo ''Irian'' Schaetz" <ir***@gmx.de>
???????:45***********************@newsspool1.arcor-online.net...And thus, ad spoke...
>I want to determinate if there no symbol in a string?
for example
"12ab34", "123a5bc", "a123c4" is ok, but "23#45", 2a,35" is not ok.
You probably want to search for "Regular Expressions". Hope that helps :-)
Flo
ad wrote:I want to determinate if there no symbol in a string?
for example
"12ab34", "123a5bc", "a123c4" is ok, but "23#45", 2a,35" is not ok.
You could use regular expressions...
Here some code demonstrating the IsValidString() function that checks
your requirements for your strings.
-----------------------------------------------
using System.Text.RegularExpressions;
private void button1_Click( object sender, EventArgs e )
{
CheckStrings();
}
static private void CheckStrings()
{
StringBuilder sb = new StringBuilder();
string[] arr = new string[]
{ "12ab34", "123a5bc", "a123c4", "23#45", "2a,35" };
foreach ( string s in arr )
{
sb.Append( s );
sb.Append( " is " );
sb.Append( IsValidString( s ) ? "OK" : "not OK" );
sb.Append( "\n" );
}
MessageBox.Show( sb.ToString() );
}
static private bool IsValidString( string s )
{
Regex re = new Regex( "^[0-9a-zA-Z]*
这篇关于如何确定字符串中是否没有符号。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!