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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String Trim

Status
Not open for further replies.

deejayAr

Technical User
Mar 20, 2008
126
US
HI
It must be easy but I'm couldn't figure it out
some one please help me
I have string
"\\aaltcad1\pciqserv\users\sdd\CADLINK\Test ARD Files\filename.xml"
I like to get
dim mypath as string = \\aaltcad1\pciqserv\users\sdd\CADLINK\Test ARD Files\
and
dim filename as string = filename.xml


thanks,
 
Dim firstString as string = yourStringsubstring(0, yourString.LastIndexOf("/")-1)

Dim secondString as string = yourStringsubstring(yourString.LastIndexOf("/"))


If [blue]you have problems[/blue], I want [green]source code[/green] AND [green]error messages[/green], none of this [red]"there was an error crap"[/red]
 
what is
yourStringsubstring

I gues you mean
dim myfilepath = myfilepathmyfile.Substring(0, myfilepathmyfile.LastIndexOf("/") - 1)

but it's give me error Argumentoutofrangeexception



 
oops, wrong slash. you want a "\", not a "/"

If [blue]you have problems[/blue], I want [green]source code[/green] AND [green]error messages[/green], none of this [red]"there was an error crap"[/red]
 
Thank you very much
it's working now

 
Unless you can guarantee 100% of the time that a "\" will be there you should do a

If myString.Contains("\") then
...
end if

to prevent a .Net runtime error when the function cannot find the \

If [blue]you have problems[/blue], I want [green]source code[/green] AND [green]error messages[/green], none of this [red]"there was an error crap"[/red]
 
Check out the path class. You can get easily get the name, extension, path, etc.

Path.GetFileName(file) will return the file name and extension without the path.

"I think we're all Bozos on this bus!" - Firesign Theatre [jester]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top