Var i As Integer = txtAccntNum.Text.IndexOfBytes( "-" ) // Find the hyphen...
// The code that does magical stuff...
// If a hyphen doesn't exist then add one...
If( i = -1 ) Then
txtAccntNumOld.Text = txtAccntNum.Text + "-01"
Else
txtAccntNumOld.Text = txtAccntNum.Text
End If
I am trying to find the hyphen in a numeric string.
Example #1: 444333-01
Example #2: 3432-03
Example #3: 12367-02
When I step through the debugger i is always -1 even though there is a hyphen in the text being examined. I have been reading through the docs but so far I have yet to find the right combination to get the result I want.
You aren‘t using RegEx at all but that’s probably irrelevant. I’m also not sure why you are using IndexOfBytes rather than IndexOf but that’s irrelevant either …
Are you sure the string you check for a hyphen really contains what you think it does? Because I see no reason why your code shouldn’t yield the expected results.
It does because I type it in prior to executing this code. I will try the IdexOf and see if that works. I just realize also that my title is incorrect… sorry.
Can you test the project I uploaded and confirm that you get -1 always with IndexOfBytes?
Could it be that you see - but could be a different character like −?
Wouldn’t this have something to do with the encoding of the text in the field? If it’s UTF-8, for instance, using indexOfBytes wouldn’t work since each character takes up two bytes.