Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to find the value of character

Status
Not open for further replies.

trueneutral

Programmer
Sep 15, 2003
13
CA
I've been pulling some data from the database, and it's returning a string of 10 characters. (I can't modify the database, so I have to do this programically) If there is no value in the string, it still returns a length 10 string with 10 invisible characters (The data type from the database is Char, and I've tried changing the values to something else, it doesn't work).

I want to try to modify this string as they're coming in. If they contain no numbers, I want to trim the string down to nothing(I've tried .trim(), it doesn't work).

So far, I can't tell what is IN the string at all. It doesn't seem to think it's a Null value, white space, punctuation etc. it seems to think EVERY character is a number even when there is definately is no numbers.

I have tried this code:


code:--------------------------------------------------------------------------------

If charAr(1).IsPunctuation(charAr(0)) = True Then Response.Write(&quot;We have a Punctuation!<BR>&quot;)
If charAr(1).IsWhiteSpace(charAr(0)) = True Then Response.Write(&quot;We have a WhiteSpace!<BR>&quot;)
If charAr(1).IsSeparator(charAr(0)) = True Then Response.Write(&quot;We have a Separator!<BR>&quot;)
If charAr(1).IsSurrogate(charAr(0)) = True Then Response.Write(&quot;We have a Surrogate!<BR>&quot;)
If charAr(1).IsSymbol(charAr(0)) = True Then Response.Write(&quot;We have a Symbol!<BR>&quot;)
If charAr(1).IsNumber(charAr(0)) = True Then Response.Write(&quot;We have a Number!<BR>&quot;)
If charAr(1).IsLetter(charAr(0)) = True Then Response.Write(&quot;We have a Letter!<BR>&quot;)

--------------------------------------------------------------------------------


And it Always returns &quot;We have a number!&quot; no matter what the content of the string may be (including letters).

I have also tried

code:--------------------------------------------------------------------------------
If charAr(1).IsNumber(charAr(0)) = True Then
temp = charAr(1).GetNumericValue(charAr(0))
If temp >= 0 And temp <= 9 Then Response.Write(&quot;We have a Number!<BR>&quot;)
End If
--------------------------------------------------------------------------------


And it still alwaysthinks it's a number, even when there is no number in there.

is there any other way to test for what the character IS in this string? Or is there a good way to showme what's in the string so I can create an if statement to ignore those characters?

Thank you, anyone who has suggestions
 
Try calling the methods like this:

Char.IsPunctuation( charAr(0) )

Also, where are the End Ifs? You should have one for each If statement.

 
I'll try that out.

But as for the End If's, you can use a single line IF statement by using THEN. So for example: If (Stuff = true) then stuff = doMoreStuff
 
&quot;But as for the End If's&quot;

Opps. Sure 'nuff. My sidebar squished your message, thus adding linebreaks to your posting and making it look a bit goofy.

Have you tried checking the values in your character array to make sure they've been properly set? I mean, you know what your If statements produce, but have you checked the contents of the array in a debug session or anything?

Also, I forgot to ask you, have you heard of &quot;regular expressions&quot; (regex) before? They'll really help you out for what you want to do. It's too much to explain in my post, but you can look up System.Text.RegularExpressions or browse the internet for some simple tutorials.
 
Hey BoulderBum,
Sorry I didn't respond earlier, I only work on weekdays :p

I tried out your Char.IsPunctuation(charAr(0)) which produced much more encouraging results (besides, it's slimmer and easier to read)

As for reading the array while debugging, that doesn't really work because my boss hasn't installed the debugging aspect of .NET because it would take a significant amount of time and space. So I have to do without for now.

But I think I got it covered, I am now able to distinguish between numbers and the filler whitespaces that are being used. I should now be able to rip out any non-number characters out of my textbox.

As for regular expressions, yes I've heard of them. I don't think they'll be necessary in this case because I can now figure out which chars are numbers, but I'll definately keep it in mind as an option if I run into trouble later on.

Thanks for your help :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top