jcampanali
asked on
Instr() Function in C#
Hello,
Converting an app from VB.NET¿C# has caused a great many errors(mostly conversion). Some however, are stumpers: for instance why can't I use similar syntactical convention when using instr()
This is VB code...
If Microsoft.VisualBasic.InSt r(txtStrik e.Text, Chr(46)) > 0 And Len(txtStrike.Text) = 5 Then
This is C# converted...
if (Strings.InStr(txtStrike.T ext, Strings.Chr(46), 1)) > 0 & Strings.Len(txtStrike.Text ) == 6) {
to which I receive 'Invalid Expression Term' error under '>' operator when building
Many thanks
Converting an app from VB.NET¿C# has caused a great many errors(mostly conversion). Some however, are stumpers: for instance why can't I use similar syntactical convention when using instr()
This is VB code...
If Microsoft.VisualBasic.InSt
This is C# converted...
if (Strings.InStr(txtStrike.T
to which I receive 'Invalid Expression Term' error under '>' operator when building
Many thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Well I did place using Microsoft.VisualBasic; so it would at least recognize the Instr() and related VB functions. I'll give a try to the above referenced.
using Microsoft.VisualBasic - good point. Sorry I hadn't thought of that.
In that case the issue is probably the single '&' sign.
In that case the issue is probably the single '&' sign.
@carl_tawn
You would probably want to include 0 in the comparison since IndexOf is index-oriented whereas InStr is position-oriented.
You would probably want to include 0 in the comparison since IndexOf is index-oriented whereas InStr is position-oriented.
txtStrike.Text.IndexOf('.') >= 0
I'm sure the likes of Redgates Reflector would make a far better conversion job than this.
You need to use - from your example:
Open in new window
by the way, why is your VB code looking for length 5 and you other version looking for length 6?