Re: How to Parse a string with Embedded Double Quotes
From: Charles Law (blank_at_nowhere.com)
Date: 11/30/04
- Next message: Robby: "Re: How to Parse a string with Embedded Double Quotes"
- Previous message: Cor Ligthert: "Re: Problem deleting Last Row in ListView"
- In reply to: Robby: "Re: How to Parse a string with Embedded Double Quotes"
- Next in thread: Robby: "Re: How to Parse a string with Embedded Double Quotes"
- Reply: Robby: "Re: How to Parse a string with Embedded Double Quotes"
- Reply: Charles Law: "Re: How to Parse a string with Embedded Double Quotes"
- Reply: Cor Ligthert: "Re: How to Parse a string with Embedded Double Quotes"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 30 Nov 2004 11:09:38 -0000
Hi Robby
Thanks for the reply. I am not sure that I understand the regular expression
> (\s*"([\s\w]*)")|(\s*(\w+))
I tried the following, but of course it gives a syntax error because of the
embedded double quotes:
Dim reg As Regex = New Regex("(\s*"([\s\w]*)")|(\s*(\w+))")
So I tried escaping the double quotes, like this
Dim reg As Regex = New Regex("(\s*""([\s\w]*)"")|(\s*(\w+))")
but this cleared my string out to a couple of spaces when I did a replace.
Any chance of a small snippet to get me on the right track, using the Match
object?
Thanks very much.
Charles
"Robby" <edmund@not.my.email.com> wrote in message
news:eCCPHps1EHA.3392@TK2MSFTNGP10.phx.gbl...
>
> Try
>
> (\s*"([\s\w]*)")|(\s*(\w+))
>
> Then do a Replace on each Match object with
>
> $2$4
>
> This will return either your double qouted string with out the qoutes or
> the word token without the whitespace characters depending on which match
> the Match object holds.
>
> You just have to love Regular Expressions.
>
> --Robby
>
>
>
>
> "Charles Law" <blank@nowhere.com> wrote in message
> news:OPAV%23Sm1EHA.3336@TK2MSFTNGP11.phx.gbl...
>> Hi Cor
>>
>> You read my mind ;-)
>>
>> I had thought of using something like #, as it will never occur in my
>> string. But then I started to look at how I would know which spaces to
>> replace with #, and which to leave. Of course, to the human eye it is
>> obvious that I only replace the spaces between " and ", but now I am back
>> to processing each part of the string character by character so that I
>> match double quotes correctly, and this is what I was trying to avoid.
>>
>> Perhaps there is a regex expression that will match double quotes, or a
>> method that parses a string taking these into account, but sadly I do not
>> know it yet.
>>
>> But please, keep the suggestions flowing.
>>
>> Charles
>>
>>
>> "Cor Ligthert" <notmyfirstname@planet.nl> wrote in message
>> news:OX3$bzk1EHA.2824@TK2MSFTNGP09.phx.gbl...
>>> Charles,
>>>
>>> I was looking at the problem, I was thinking will I give my answer
>>> because it is so difficult to describe. Than I saw that it was you.
>>> Therefore it should not be a problem.
>>>
>>> In this kind of situations I replace the spaces I will not use for an
>>> absolute unused character.
>>>
>>> Do the split
>>>
>>> And replace the unused character again back for a space
>>>
>>> I assume that this is for you more than enough explanation.
>>>
>>> And now you read this you say, I knew that as well.
>>>
>>> :-)))
>>>
>>> Cor
>>>
>>> "Charles Law" <blank@nowhere.com>
>>>
>>> ...
>>>>I have a string similar to the following:
>>>>
>>>> " MyString 40 "Hello world" all "
>>>>
>>>> It contains white space that may be spaces or tabs, or a combination,
>>>> and I want to produce an array with the following elements
>>>>
>>>> arr(0) = "MyString"
>>>> arr(1) = 40
>>>> arr(2) = "Hello world"
>>>> arr(3) = "all"
>>>>
>>>> Using trim and a regular expression ("\s+"), I can reduce my string to
>>>>
>>>> "MyString 40 "Hello world" all"
>>>>
>>>> and with Split I can get
>>>>
>>>> arr(0) = "MyString"
>>>> arr(1) = 40
>>>> arr(2) = ""Hello"
>>>> arr(3) = "world""
>>>> arr(4) = "all"
>>>>
>>>> As you can see, it is not quite what I need. The spaces in "Hello
>>>> world" have been reduced to a single space, and Split does not respect
>>>> the double quotes, and splits "Hello world" over two elements.
>>>>
>>>> Does anyone have an idea how I could do this? I could process the
>>>> string character by character, but I am hoping that there is a
>>>> straight-forward technique for doing it, without looping, and using
>>>> some of the techniques I already have.
>>>>
>>>> TIA
>>>>
>>>> Charles
>>>>
>>>>
>>>
>>>
>>
>>
>
>
- Next message: Robby: "Re: How to Parse a string with Embedded Double Quotes"
- Previous message: Cor Ligthert: "Re: Problem deleting Last Row in ListView"
- In reply to: Robby: "Re: How to Parse a string with Embedded Double Quotes"
- Next in thread: Robby: "Re: How to Parse a string with Embedded Double Quotes"
- Reply: Robby: "Re: How to Parse a string with Embedded Double Quotes"
- Reply: Charles Law: "Re: How to Parse a string with Embedded Double Quotes"
- Reply: Cor Ligthert: "Re: How to Parse a string with Embedded Double Quotes"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|