Link to home
Start Free TrialLog in
Avatar of cmdolcet
cmdolcetFlag for United States of America

asked on

Parsing out String

How can I parse out a string but only keep the last half of data. I only want the test1.dfq

C:\documents and settings\username\desktop\test1.dfq

Avatar of Trideep Patel
Trideep Patel
Flag of India image

Try This

    Dim str As String
    str = "C:\documents and settings\username\desktop\test1.dfq"

    str.Substring(str.LastIndexOf("\") + 1, str.Length - str.LastIndexOf("\") - 1)
ASKER CERTIFIED SOLUTION
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try this....
        Dim filepath As String = "C:\documents and settings\username\desktop\test1.dfq"
        Dim filename As String = filepath.Substring(filepath.LastIndexOf("\") + 1)

Open in new window

Hi,

try:

            string path = @"C:\documents and settings\username\desktop\test1.dfq";

            string file = System.IO.Path.GetFileName(path);

            MessageBox.Show(file);


J
Hi,

sorry, in VB this would be

Dim path as String = "C:\documents and settings\username\desktop\test1.dfq"

Dim file as String = System.IO.Path.GetFileName(path)

System.IO.Path.GetFileName(path)

J