Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pulling middle part of dynamic string 1

Status
Not open for further replies.

slybitz

Technical User
Mar 25, 2005
113
US
So I have a string of text that I have pulled from a textbox. I want to be able to pull out the middle characters from this string and use them. The only thing is that the middle characters are going to change in length so it's not always going to be a set length. But the middle characters will always be enclosed by "\" before the first middle character that I want and "\" after the end of the last middle character that I want. So for example I have a string that looks like:

abcd efg\hijk\lmno

...I want to be able to pull out "hijk" and put that into another string. How can I do this?

Thanks for the help!
 
Code:
public function GetMiddle(Value as string)
 dim sReturn as string = string.empty
' Value = "abcd efg\hijk\lmno"
 dim sParts() as string = Value.Split("\")

 if sParts.length = 3 then
   sReturn = sParts(1)
 else
   dim excBadFormat as new exception("The provided string could not be split correctly")
   throw excBadFormat
 end if

 return sReturn
end funciton

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Works perfectly. Thank you very much. Star for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top