0

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.

After converted by convert(), if there are blank characters found, the source string will be convert to byte array.

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

And now I need determine the source string is valid or invalid based on the converted result. I dont' know how to say the result is an byte array. Could you please give me some advice. Thanks in advance.

input string type source value as 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.

1
  • Can you show more code and explain better what you are trying to accomplish? Your convert function would be helpful. Commented Jun 12, 2011 at 1:41

3 Answers 3

1

maybe use:

        if (ResultVal is byte[]) {
           // SourVal is Invalid;
        } else if ( ResultVal is String ) { 
            //SourVal is valid;
        }
Sign up to request clarification or add additional context in comments.

1 Comment

ResultVal is List<byte>. Works on my case. Thanks.
1

Try using IsWhiteSpace

1 Comment

IsWhiteSpace is a good method I never used. But I maybe can't use it in my practice. I need to handle the ResultVal as the arguments. There is no White space any more. Thanks.
1
//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

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.