Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

im trying to save the text from a string as

 

"c:\program files"

 

but when i do this

 

chr(windows.systems.forms.keys.oemquote) & "c:\program files" &

chr(windows.systems.forms.keys.oemquote)

 

i end up with a funky result

  • Administrators
Posted

Dim s As String = Convert.ToChar(34) & "c:\program files" & Convert.ToChar(34)

would work, although this does rely on you guessing the correct location for the program files folder...

A better soulution would be to use

Dim s As String = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

  • Leaders
Posted

Why are either of you using a function to place quotes in strings? Plausibly Damp is right about the Environment.GetFolderPath function. If you must include quotes in your string, however, do it like this:

 

Dim s As String = """C:\Program Files"""

 

The double double quotes inside the outmost quotes will be parsed by the compiler as single double quotes... almost like an escape sequence. It looks confusing, but try it.

[sIGPIC]e[/sIGPIC]
  • Leaders
Posted

In your origional message:

im trying to save the text from a string as

 

"c:\program files"

you used "double quotes". If you want "double quotes" then enter the string like
Dim s As String = """this""" '= "This"

If you want 'single quotes' (which i don't think you do) then enter the string like

Dim s As String = "'this'" '= 'This'

If you mean something else then I don't follow.

[sIGPIC]e[/sIGPIC]
Posted

ok, im still not getting this right.

 

 

what im trying to do, is list a number of aliases into a list box. this gets done by loading a text file, and looking at each line for the word "*commandalias". I then split the alias into a list array by the following

 

 

dim list() as string
list = split(newline, " " )

 

 

what i need to do then is remove the quotes from the string in the text file. im currently doing the following

 

                       Dim str As String
                       Dim newstr As String
                       Dim id As Integer

                       Do While InStr(list(1), Windows.Forms.Keys.OemQuotes) <> -1
                           id = InStr(list(1), Windows.Forms.Keys.OemQuotes)
                           str = Mid(list(1), id + 1, Len(list(1)))
                           list(1) = str
                       Loop

the problem im having is that it doesnt remove anything. If i replace the

 

str = Mid(list(1), id + 1, Len(list(1))) with

str = Mid(list(1), id + 2, Len(list(1)))

 

 

I remove quotes from most strings but then i start removing the actual word. such as """""word""" ends up "ord"

  • Administrators
Posted

Don't use the Windows.forms.Keys enumeration in place of ascii characters, it reports the keyboard scan code not the ASCII character.

Use either the syntax I posted above or the solution offered by marble eater - they will work with embedded quotes correctly.

 

Rather than using mid you may want to look at the .SubString method of your string variable, also remember the indexes into the string are 0 based, if you want to start at the 4th letter for example you need to specify a start index of 3.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...