Results 1 to 6 of 6

Thread: How to define If string contains something.

  1. #1

    Thread Starter
    Lively Member FireDust's Avatar
    Join Date
    Feb 2013
    Location
    Slovakia
    Posts
    112

    Question How to define If string contains something.

    By the title you may be thinking of .Contains. But that will not work here. I need to define If the Path that I have leads to .Ink or directly to .Exe file. If I try Path.Contains(".Ink"), It wont work because it takes the name of the file and ads .Ink at the end. Example:
    Code:
    Path = "C:\Application.Ink"
    If Path.Contains(".Ink") Then
        Code...
    End If
    But this wont work, and I know why, but I dont know any other command how to do it.
    Please help.

  2. #2
    Lively Member
    Join Date
    Apr 2011
    Posts
    75

    Re: How to define If string contains something.

    INK or LNK ?

  3. #3
    Fanatic Member
    Join Date
    Dec 2007
    Location
    West Yorkshire, UK
    Posts
    791

    Re: How to define If string contains something.

    I don't understand your explanation, sorry. However, while you wait for more replies, the file extension is probably wrong. If you're after the extension for a shortcut, it is "lnk" ie, the first, third and fourth letters of the word "link". You have used capital i instead of lower case l.

  4. #4

    Thread Starter
    Lively Member FireDust's Avatar
    Join Date
    Feb 2013
    Location
    Slovakia
    Posts
    112

    Re: How to define If string contains something.

    Ok, So what I need is to tell the application when the path is leading to .exe or .ink (Shortcut).

  5. #5
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: How to define If string contains something.

    Quote Originally Posted by FireDust View Post
    Ok, So what I need is to tell the application when the path is leading to .exe or .ink (Shortcut).
    If you want to know what the file extension is then try, IO.Path.GetExtension(). And I'm guessing you actually mean "LNK" not "INK"?

    Code:
    Dim filePath = "C:\Application.Lnk"
    ' get file extension of path in upper case
    Dim fileExtension = IO.Path.GetExtension(filePath).ToUpper
    
    ' compare
    If fileExtension = ".LNK" Then ' shorcut link
        Debug.WriteLine("Link file")
    ElseIf fileExtension = ".EXE" Then 'executable
        Debug.WriteLine("Executable file")
    End If
    Last edited by Edgemeal; Feb 24th, 2013 at 06:06 AM.

  6. #6

    Thread Starter
    Lively Member FireDust's Avatar
    Join Date
    Feb 2013
    Location
    Slovakia
    Posts
    112

    Re: How to define If string contains something.

    Yea, sorry. :P
    But thanks for the answer. Really helped me alot.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width