By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,219 Members | 2,423 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,219 IT Pros & Developers. It's quick & easy.

single line string maninuplation substring, trim, indexof ?

P: n/a
I have a string that looks like this?

ihelloworld_zzz_yyy

In a single vb.net line, I want to remove the frist character and
anything after and including the first "_"

resulting in :

helloworld

I've been trying things like this:

Dim cleanname = c.ID.Remove(1).Substring(0, c.ID.IndexOf("_"c))

Dim cleanname = c.ID.subsrting(1,c.id.Length).Substring(0,
c.ID.IndexOf("_"c))

the error I get is that the index is out of bounds becasue it's a
substring of a substring and the index I guess has changed.

thanks.

Nov 11 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Jason,

Without testing,

myNewString as string = "ihelloworld_zzz_yyy".Substring(1,10)

I hope this goes,

Cor
>
In a single vb.net line, I want to remove the frist character and
anything after and including the first "_"

resulting in :

helloworld

I've been trying things like this:

Dim cleanname = c.ID.Remove(1).Substring(0, c.ID.IndexOf("_"c))

Dim cleanname = c.ID.subsrting(1,c.id.Length).Substring(0,
c.ID.IndexOf("_"c))

the error I get is that the index is out of bounds becasue it's a
substring of a substring and the index I guess has changed.

thanks.

Nov 11 '06 #2

P: n/a
sorry, the helloworld string is an example and might be longer or
shorter.
Cor Ligthert [MVP] wrote:
Jason,

Without testing,

myNewString as string = "ihelloworld_zzz_yyy".Substring(1,10)

I hope this goes,

Cor

In a single vb.net line, I want to remove the frist character and
anything after and including the first "_"

resulting in :

helloworld

I've been trying things like this:

Dim cleanname = c.ID.Remove(1).Substring(0, c.ID.IndexOf("_"c))

Dim cleanname = c.ID.subsrting(1,c.id.Length).Substring(0,
c.ID.IndexOf("_"c))

the error I get is that the index is out of bounds becasue it's a
substring of a substring and the index I guess has changed.

thanks.
Nov 11 '06 #3

P: n/a
Try:

Dim str As String = "ihelloworld_zzz_yyy"

str = str.Substring(1, str.IndexOf("_") - 1)

Thanks,

Seth Rowe
Jason wrote:
sorry, the helloworld string is an example and might be longer or
shorter.
Cor Ligthert [MVP] wrote:
Jason,

Without testing,

myNewString as string = "ihelloworld_zzz_yyy".Substring(1,10)

I hope this goes,

Cor
>
In a single vb.net line, I want to remove the frist character and
anything after and including the first "_"
>
resulting in :
>
helloworld
>
I've been trying things like this:
>
Dim cleanname = c.ID.Remove(1).Substring(0, c.ID.IndexOf("_"c))
>
Dim cleanname = c.ID.subsrting(1,c.id.Length).Substring(0,
c.ID.IndexOf("_"c))
>
the error I get is that the index is out of bounds becasue it's a
substring of a substring and the index I guess has changed.
>
thanks.
>
Nov 11 '06 #4

P: n/a
>In a single vb.net line,

Why is the number of lines important to you? I would think readability
and correctness mattered more.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 11 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.