English 中文(简体)
C#的证明价值验证
原标题:string value validation in C#

There is two variable was assigned the value of "003" and "00 3". And it was convert to byte[] as below.

Before:

myStr1 = "003"; // valid, there is no blank inserted.
myStr2 = "00 3"; // invalid, there is one blank character or multi blanks character inserted.

在转换后,如果发现有空白特性,则源体将改成星体。

myVal1 = "3";  // valid after convert
myVal2[0] = 0; // invalid, since the source myStr2 is invalid.
myVal2[1] = 1; // same as above.

现在,我需要根据换算结果确定消息来源是否有效或无效。 我很想知道,如何说结果是一阵列。 请让我提出一些建议。 提前感谢。

显示SourVal型源价值

if (ResultVal is Byte Array) // how to translate the statement to C# code?
   SourVal is Invalid;
else if (ResultVal is still String type) // how to translate the statement to C# code?
   SourVal is valid;

ps: I failed to try the methods of typeof() and gettype() at my practice. I don t know how to use the methods. Or there is other better method for my validation.

最佳回答

可能使用:

        if (ResultVal is byte[]) {
           // SourVal is Invalid;
        } else if ( ResultVal is String ) { 
            //SourVal is valid;
        }
问题回答

Try using

//Check the String for Blank spaces if found then don t convert

if(!str.Contains(" "))

{

//use the convert method 

}
else

{

//Write Message for an Invalid String

}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签