Re: String Operation in C#
- From: "Nicholas Paldino [.NET/C# MVP]" <mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 15 Oct 2005 10:35:53 -0400
Rhonda,
Do you know that the number always comes first, and has a space after
it? If so, I would get the index of the first space, and the first
underscore, and then get the substring using those two indexes, like this:
// Assuming str has your string, you could do:
// The index of the space.
int spaceIndex = str.IndexOf(' ');
int ulIndex = str.IndexOf('_');
// Get the substring based on the indexes.
subStr = str.Substring(str.IndexOf(' ') + 1, ulIndex - spaceIndex - 1);
This assumes there is always a single space before the beginning of the
section you want to get, and an underscore immediately following it.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx
"Rhonda Tipton" <Rtipton12@xxxxxxxxxx> wrote in message
news:Lf84f.37887$Q53.6561@xxxxxxxxxxxxxxxxxxxxxxx
> Hello.
>
> I am trying to do a substring or something like that to extract the middle
> portion of a string.
>
> 12345 TEST FACILITY 1_Letter 1A
> 12346 TEST FACILITY 2_Letter 1A
>
> I would like to be able to extract the part after the number and before
> the _.
>
> TEST FACILITY 1
> TEST FACILITY 2
>
> I am new to C# and still learning, so any help is greatly appreciated.
>
> Rt
>
.
- Follow-Ups:
- Re: String Operation in C#
- From: Rhonda Tipton
- Re: String Operation in C#
- References:
- String Operation in C#
- From: Rhonda Tipton
- String Operation in C#
- Prev by Date: String Operation in C#
- Next by Date: Re: Marshaling Delegates as Struct/Class Members
- Previous by thread: String Operation in C#
- Next by thread: Re: String Operation in C#
- Index(es):
Relevant Pages
|