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!

regex problem

Status
Not open for further replies.

hlybbi

Programmer
Mar 19, 2003
91
IS
i have a sting witch i need to divide into 3 groups

/files/images/image.jpp

1. Location: /files/images/
2 file name: image
3 file type: .jpp

this is my code

FileName = Regex.Replace(pic, @"^.*\\", ""); // here is the problem
uploadpath = Regex.Replace(pic, FileName, "");
string[] temp = Regex.Split(pic, "\\.");
FileName = temp[0];
Type = temp[1];

please help ;(

Best regards Hlynur
 
Hi I wouldn't use Regex at all for your problem. I would simply use the split function.

String pic="/files/images/image.jpg";
String[] splitPath=pic.Split('/');
String FullFileName=splitPath[splitPath.Length-1];
String FileName=FullFileName.Split('.')[0];
String FileType=FullFileName.Split('.')[1];
String Path="/";
for (int i=0;i<splitPath.Length-1;i++) {
Path+=splitPath;
Path+=&quot;/&quot;;
}

Depending on your needs you might want to use the StringBuilder Class in the for loop.

Didn't really testthis but it should work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top