String Manipulation

Chrisaldi

Active member
Joined
Jan 30, 2004
Messages
26
This is the problem:

I have a string :

"The Quick [Brown] fox jumps over the laxy dog."

I have to get only the word Brown, How can I do it?
but I want it in C# code. Can anyone help me in this?

Thanks!!
 
Sorry I can only do this in vb, but it shouldnt be hard to convert to c#. Something like:

Code:
Dim fullText as string = "The Quick [Brown] fox jumps over the laxy dog."
Dim inBrackets as string = fullText.substring(fullText.IndexOf("["), fullText.IndexOf("]") - fullText.IndexOf("["))

Its not tested but it should work (you may need a -1 in that last bit, I always get confused with character indexes like this). Note that it presumes itll find text between [ and ] or itll fail - you may want to put this inside a Try... Catch statement.
 
Good topic! I have the same question but my string is a bit different:

PHP:
Dim fullText As String = "#1#dennis;peter#2#Matt;Frank#....etc."

Now i want the part between #1# till the next #. It wont work with this function (i get back a empty string):

PHP:
Dim inBrackets As String = fullText.Substring(fullText.IndexOf("#1#"), fullText.IndexOf("#") - fullText.IndexOf("#1#"))

Can somebody help me with this one?
 
The problem was that your IndexOf("#") was returning the position of the first "#" in the "#1#" part of the string. Try:
Code:
Dim inBrackets as String = fullText.SubString(fullText.IndexOf("#1#") + 3)
inBrackets = inBrackets.Substring(0,inBrackets.IndexOf("#"))
 
Back
Top