简体   繁体   English

如果ASCII字符串包含字母或数字,则返回文本

[英]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.

相关问题 如果字符串的长度为2并且包含1个字母和1个数字,则正则表达式匹配 - Regex match if a string has length 2 and contains 1 letter and 1 number 检查字符串是否至少包含以下各项之一:小写字母、大写字母、数字和特殊字符 - Check if string contains at least one of each: lowercase letter, uppercase letter, number, and special character 如果字符串包含字母,则抛出错误? - If string contains a letter, throw error? 检查文本是否包含字符串 - Check that the text contains a string .Net MVC 2,返回文件名中包含非ASCII字符的文件 - .Net MVC 2, return File that contains non-ASCII characters in the filename 我如何检查一个字符串包含一个字母空格字母空格和另一个字母 C# - How can i check of a string contains a letter space letter space and anotherl letter C# 输入字符串包含非ASCII或空字符 - The input string contains non-ASCII or null characters 字符串数组:搜索文本,返回第一次出现的行号 - String array: search for text, return line number of first occurrence 用于检查字符串是否以],字母和数字开头的正则表达式模式 - Regex pattern for checking if a string starts with ], a letter and a number 按字母然后数字按字符串字段对对象列表进行排序? - Sorting a list of objects by a string field by letter then number?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM