C#Windows应用程序验证 [英] C# windows application Validation

查看:68
本文介绍了C#Windows应用程序验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我有下面这样的字符串
字符串STR ="0004168858,AB0688120881,15,PLATE CLAMPING CO,KTL 16,CEQP,GI31,1111,DV1111,22222222"

现在,我想用STR验证输入字符串,其中有这么多字段用逗号分隔符

在此STR中有10个字段,所以我要检查新字符串中是否有10个字段
是否

那我该怎么写代码
请帮忙

谢谢与问候
Indrajit Dasgupta

Hi All
I have string like below
string STR="0004168858,AB0688120881,15,PLATE CLAMPING CO,KTL 16,CEQP,GI31,1111,DV1111,22222222"

Now I want to validate the input string with STR that this much field is there with comma separator

In this STR 10 fields are there so I want to check in my new string is there 10 fields
or not

So how should I write code for that
Please help

Thanks & Regards
Indrajit Dasgupta

推荐答案

尝试:
string STR="0004168858,AB0688120881,15,PLATE CLAMPING CO,KTL 16,CEQP,GI31,1111,DV1111,22222222";
string[] parts = STR.Split(',');

这会将每个元素分解为数组中的单独字符串

This will break each element into a separate string in the array


根据您的最新注释,您需要验证用逗号分隔的子字符串的数量在主字符串STR中.
Based on your latest comment, you need to validate the count of substring separated by comma in the main string STR.
STR.Split(',').Count() 

上面的代码将为您提供主字符串中子字符串的计数.
现在,如果您想通过某种验证控件进行验证,则可以将ErrorProvider控件用于Windows应用程序.在 http://www.c-sharpcorner.com/UploadFile/中查找错误提供程序的更多详细信息scottlysle/UseErrorProvider03082007210138PM/UseErrorProvider.aspx [ ^ ]

希望有帮助.

Milind

Above code will give you the count of the substrings in the main string.
Now if you want to validate through some kind of validation control, then you can use ErrorProvider control for windows application. Look for more details of error provider at http://www.c-sharpcorner.com/UploadFile/scottlysle/UseErrorProvider03082007210138PM/UseErrorProvider.aspx[^]

Hope that helps.

Milind


要检查您的新字符串是否有10个字段,只需将字符串拆分并通过其arr.lenght属性获取数组计数.

谢谢,
Ambesha
To check that your new string have 10 feild or not just split the string and get count of array by its arr.lenght proprety.

Thanks,
Ambesha


这篇关于C#Windows应用程序验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆