How to translate VB code InStr(1, sDocName, """") to C#

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi there, how do I translate the following vb code to C#? I know to use
Indexof, but what would be for """"? Thanks!

InStr(1, sDocName, """")
 
cloudx said:
hi there, how do I translate the following vb code to C#? I know to use
Indexof, but what would be for """"? Thanks!

InStr(1, sDocName, """")

Hi, they are looking for a double quote char in the string, so you would use
"\"" in C#. Don't forget that VB indexes are 1-based, so the equivalent
index in C# would be 0 (assuming they didn't specify Option Base 0).

-- Alan
 
1. IndexOf's 'start' parameter is 0-based, while InStr is 1-based.
2. If you're converting existing code, then you'll also have to add 1 to the
result since InStr's result is 1-based while IndexOf's result is 0-based.

So, unless you're rewriting the surrounding code (instead of just converting
it), the correct translation is:

i = sDocName.IndexOf("\"", 0) + 1;

David Anton
www.tangiblesoftwaresolutions.com
Home of the Instant C# VB.NET to C# converter
and the Instant VB C# to VB.NET converter
 
Back
Top