string parsing ques

M

mp

Hi
looking for equivalents to vb6 instr and Mid$
been looking through the help but haven't found it yet, will keep looking
but if anyone feels like offering a tip of where to look?

I want to find a substring inside a string, for example
string = "the brown fox"
string2 = .After("the") and .Before ("fox") = "brown"
how to implement After and Before is what i'm looking for

thanks
mark
 
A

Alan Pretre

mp said:
I want to find a substring inside a string, for example
string = "the brown fox"
string2 = .After("the") and .Before ("fox") = "brown"
how to implement After and Before is what i'm looking for

See Substring() and IndexOf().

-- Alan
-- cleartopartlycloudy.blogspot.com
 
M

Michelle

I want to find a substring inside a string, for example
string = "the brown fox"
string2 = .After("the") and .Before ("fox") = "brown"
how to implement After and Before is what i'm looking for

Take a look at string.Substring.

Michelle
 
P

Peter Duniho

Hi
looking for equivalents to vb6 instr and Mid$
been looking through the help but haven't found it yet, will keep looking
but if anyone feels like offering a tip of where to look?

I want to find a substring inside a string, for example
string = "the brown fox"
string2 = .After("the") and .Before ("fox") = "brown"
how to implement After and Before is what i'm looking for

The literal equivalents are, as others have suggested, IndexOf(),
LastIndexOf(), and Substring() for finding the first occurrence of a
string, the last occurrence of a string, and extracting a substring from a
string, respectively (IndexOf() and LastIndexOf() also provide overloads
that let you say where to start the search, so that iterative searches can
find all of a given string).

However, given your elaboration on the question, you are definitely
getting into Regex territory. The Regex class provides a syntax to
describe the relationship you're talking about in a less imperative way,
and then to use that relationship to automatically search for and find the
piece of text you're looking for.

For the exact example, you may still find the String methods concise
enough. But for anything more complicated, you should consider becoming
familiar with the Regex class.

Pete
 
M

mp

Peter Duniho said:
snip>
However, given your elaboration on the question, you are definitely
getting into Regex territory. The Regex class provides a syntax to
describe the relationship you're talking about in a less imperative way,
and then to use that relationship to automatically search for and find the
piece of text you're looking for.

For the exact example, you may still find the String methods concise
enough. But for anything more complicated, you should consider becoming
familiar with the Regex class.

Pete

after posting i realized that was probably the unfortunate answer :)
have looked at regex in past and got a headache, guess i have to get over it
:)
thanks
mark
 
M

mp

Alan Pretre said:
See Substring() and IndexOf().

-- Alan
-- cleartopartlycloudy.blogspot.com

sheesh, i'd seen those and then forgot about them, duh!
thanks
mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top