[英]If ASCII String Contains Letter or Number, Then Return Text
Still working on my project, and would like some more help. 仍在从事我的项目,并希望获得更多帮助。 Here's my problem: I have a string of chars in CompanyID
that may be full of " " spaces (derived from ASCII hex text). 这是我的问题:我在CompanyID
中有一个字符字符串,可能充满“”空格(源自ASCII十六进制文本)。 Some code I've tried won't detect the spaces (possibly because there's many hex characters that return spaces with different values), and the code (FIG B.) returns a value of all spaces. 我尝试过的某些代码无法检测到空格(可能是因为有许多十六进制字符返回具有不同值的空格),并且代码(图B.)返回了所有空格的值。 What I would like to do is search the string 'CompanyID' for any Letter/Number. 我想做的是在字符串“ CompanyID”中搜索任何字母/数字。 If true, I need textBox10.Text = CompanyID;
如果为true,则需要textBox10.Text = CompanyID;
If not, I need to have output to a textbox as shown in Fig, A. 如果没有,我需要输出到图A所示的文本框。
FIG. 图。 A: A:
else textBox10.Text = "No Value!";
if (val.Contains("No Value!")) textBox10.ForeColor = Color.Orange;
FIG. 图。 B: B:
// COMPANY ID
{
BinaryReader br3 = new BinaryReader(File.OpenRead(OpenFileDialog1.FileName));
br3.BaseStream.Position = 0x110;
Char[] charArray = br3.ReadChars(16);
string CompanyID = new string(charArray);
textBox10.ForeColor = Color.Black;
textBox10.Text = CompanyID;
br3.Close();
{
// CODE REPLACEMENT
string val = CompanyID;
textBox10.ForeColor = Color.Black;
foreach (char c in CompanyID)
{
if (Char.IsDigit(c)) textBox10.Text = CompanyID;
else textBox10.Text = "No Value!";
if (val.Contains("No Value!")) textBox10.ForeColor = Color.Orange;
}
}
Any help would be appreciated. 任何帮助,将不胜感激。 Thank you for your time! 感谢您的时间!
I used the following code to solve my problem. 我使用以下代码解决了我的问题。 Someone suggested using IsWhiteSapce
to detect if there was anything in a string (even tho the post got somehow deleted), and its been working for me. 有人建议使用IsWhiteSapce
来检测字符串中是否有任何内容(甚至帖子以某种方式被删除了),并且它对我IsWhiteSapce
。 Thanks for the peeps who replied. 谢谢那些偷窥的人。
// DESCRIPTION
{
BinaryReader br7 = new BinaryReader(File.OpenRead(OpenFileDialog1.FileName));
br7.BaseStream.Position = 0x1c8;
Char[] charArray = br7.ReadChars(40);
string Desc = new string(charArray);
textBox11.Text = Desc;
if (textBox11.Text.All(c => char.IsWhiteSpace(c)))
{
textBox11.ForeColor = Color.Orange;
textBox11.Text = "No Value!";
}
else textBox11.ForeColor = Color.Black;
br7.Close();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.