Selecting a portion of a string

  • Thread starter Thread starter jasperjoe
  • Start date Start date
J

jasperjoe

This is a bit of a strange question, I hope someone can help me out on
this as I'm completely stumped.

I have a string that is: bttn1-ITEM1

Is there a way I can read this string so I just get the "ITEM1" bit? I
want to read the bit after the hyphen each time.

e.g.

"bttn2-ITEM3" = "ITEM3"
"bttn14-ITEM27" = "ITEM27"

I'd really appreciate it if anyone can help me out on this one.
 
Dim nHyphen As Integer
Dim cText as String

cText = "bttn2-ITEM3"
nHyphen = cText.IndexOf("-")
MsgBox(cText.Substring(nHyphen + 1))

Of course you can write it in one line: cText.Substring(cText.IndexOf("-") +
1).
 
I have a string that is: bttn1-ITEM1

Is there a way I can read this string so I just get the "ITEM1" bit? I
want to read the bit after the hyphen each time.

e.g.

"bttn2-ITEM3" = "ITEM3"
"bttn14-ITEM27" = "ITEM27"

\\\
Dim s As String = "bttn2-ITEM3"
Dim t As String = Mid(s, InStr(s, "-") + 1)
///
 
Don't add your e-mail address to any post because you are opening yourself to
a lot of SPAM.
 
Crouchie,

That are methods as part of the Microsoft.VisualBasic namespace, you can use
those by instance in C# as well.

Cor
 
Crouchie1998 said:
Don't add your e-mail address to any post because you are opening yourself
to
a lot of SPAM.

My email address does exist, but I don't read mails sent to it. By posting
with a valid email address, I have the possibility of easily removing
You are still using the VB6 way of doing things I see. :)

LOL -- I am always choosing the simpler solution!
 
Herfried K. Wagner said:
My email address does exist, but I don't read mails sent to it. By
posting with a valid email address, I have the possibility of easily
removing messages from the Google Groups archive


LOL -- I am always choosing the simpler solution!

You mean....

If it ain't broke....... why the hell did they change the damn syntax?

Or that's what I sometimes think anyhow.
 
Of course you can go the old VB 6 route for syntax, but why has it changed if
no one will use it.
 
Crouchie,

Did you know that a rich language has always more words to describe the same
things?

You can compare the VB language with that.

Just my opinion as I often wrote about this.

Cor
 
Andy O'Neill said:
You mean....

If it ain't broke....... why the hell did they change the damn syntax?

They didn't change the syntax. The .NET Framework provides a "low-level"
class library that can be used by different programming languages. Some
programming languages "override" these low-level Framework features by
providing their own wrappers and extensions that fit better into the
programming language and make the developer more productive.

The most important thing is that different programming languages base their
features on the same classes of the .NET Framework instead of implementing,
for example, strings on their own. This guarantees language
interoperability.
 

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

Back
Top