[Gambas-user] Select Case problem
Tobias Boege
taboege at ...626...
Thu Mar 28 10:20:46 CET 2013
On Thu, 28 Mar 2013, Tobias Boege wrote:
> On Thu, 28 Mar 2013, Bruce wrote:
> > On Thu, 2013-03-28 at 17:05 +1030, Bruce wrote:
> > > Hi,
> > >
> > > I am trying to parse a text file that contains key,value pairs like:
> > > Name=Malarky
> > > Size=10
> > > BackImage[N]=sometext
> > > FrontImage[S]=sometext
> > > etc
> > > using a construct like
> > > For idx = 0 to sourcearray.max
> > > Select Upper(Split(SourceArray[idx],"+")[0])
> > > Case "NAME"
> > > blah blah
> > > Case "SIZE"
> > > blah blah
> > > Case Like "BACKIMAGE[*]"
> > > blah blah
> > > Case Like "FRONTIMAGE[*]"
> > > blah blah
> > > End Select
> > > Next
> > >
> > > This fails because Case Like "BACKIMAGE[*]" is being interpreted as a
> > > regular expression where I need to escape the regexp "[]" meaning.
> > >
> > > Trying to use escapes like
> > > Case Like "BACKIMAGE\[*\]"
> > > fails as \[ is an unknown escape sequence.
> > >
> > > Any clues?
> > >
> > > tia
> > > Bruce
> > >
> >
> > Sorry, I have over simplified that. I also need to discern lines like
> > BACKIMAGE[*]
> > from lines like
> > BACKIMAGE[*][*]
> > so
> > Like "BACKIMAGE*"
> > wont work.
> >
> > B
>
> OK. If the lines above (from your most recent mail) are literal strings,
> then you'll need something like:
>
> Case Like "BACKIMAGE\\[*\\]" ' The compiler transforms "\\" to a literal "\"
> ' so that you end up with the right expression.
>
> to match "BACKIMAGE[*]" but since you want to distinguish between, e.g.
> "BACKIMAGE[*]" and "BACKIMAGE[*][*]" - why would you use "Case Like", i.e. a
> regular expression at all? These are distinct strings you want to keep
> distinct, no need to group them by regular expressions then?
Oops, since you want "[*]" literal at the end of your strings which are
actually three characters with special LIKE meaning, you must use:
Case Like "BACKIMAGE\\[\\*\\]"
Just in case you still need regular expressions and I misunderstood
something.
Regards,
Tobi
More information about the User
mailing list