如何确定字符串中是否没有符号。

编程入门 行业动态 更新时间:2024-10-28 06:23:07
本文介绍了如何确定字符串中是否没有符号。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想确定字符串中是否没有符号? 例如 " 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 ...

因此,广告发言......

>我想确定字符串中是否没有符号?例如" 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...

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]*

更多推荐

如何确定字符串中是否没有符号。

本文发布于:2023-10-29 20:40:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1540693.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   符号

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!