Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Finding File Paths from string

Finding File Paths from string

Scheduled Pinned Locked Moved C#
help
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    abhinish
    wrote on last edited by
    #1

    hi guys ! need some help i have to find out the file paths between string which has to be taken from User from a richtextbox the problem is there is no specified location on which the user will type the path .. it can be any where in the string for eg. user entered data something like this :

    If the above link is not visible then run the application “C:\Program Files\CasinoOnNet\Unwise.exe” and follow the instructions to uninstall the Casino on Net.

    i have to find “C:\Program Files\CasinoOnNet\Unwise.exe” in this string. these paths can be more than one and it is not necessary that they are in Quotes.. is there any way to find such paths .. any idea abhinav

    R D L 3 Replies Last reply
    0
    • A abhinish

      hi guys ! need some help i have to find out the file paths between string which has to be taken from User from a richtextbox the problem is there is no specified location on which the user will type the path .. it can be any where in the string for eg. user entered data something like this :

      If the above link is not visible then run the application “C:\Program Files\CasinoOnNet\Unwise.exe” and follow the instructions to uninstall the Casino on Net.

      i have to find “C:\Program Files\CasinoOnNet\Unwise.exe” in this string. these paths can be more than one and it is not necessary that they are in Quotes.. is there any way to find such paths .. any idea abhinav

      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #2

      A simplistic approach that (may) provide reasonably good results is:

      search for the first occurence of a backslash character (\);
      if (found) {
      rewind to first previous space;
      extract substring to next space (or end of string);
      in source string, replace substring with empty string;
      return substring;
      }
      return "";

      PS: This is highly NOT a perfect solution. In particular, it won't properly handle paths containing embedded spaces. /ravi My new year's resolution: 2048 x 1536 Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

      1 Reply Last reply
      0
      • A abhinish

        hi guys ! need some help i have to find out the file paths between string which has to be taken from User from a richtextbox the problem is there is no specified location on which the user will type the path .. it can be any where in the string for eg. user entered data something like this :

        If the above link is not visible then run the application “C:\Program Files\CasinoOnNet\Unwise.exe” and follow the instructions to uninstall the Casino on Net.

        i have to find “C:\Program Files\CasinoOnNet\Unwise.exe” in this string. these paths can be more than one and it is not necessary that they are in Quotes.. is there any way to find such paths .. any idea abhinav

        D Offline
        D Offline
        DigitalKing
        wrote on last edited by
        #3

        Use Regular Expressions: using System.Text.RegularExpressions; ... //Find all paths in the string MatchCollection matches = Regex.Matches(richTextBox1.Text, "\\b[a-z]\\:(\\\\[^\\n\\r\\f\\t\\\\/<>|\":*?]+)*\\b", RegexOptions.IgnoreCase); foreach (Match m in matches) { //do whatever you need to for each path found in the string. The entire path can be found using m.Value //you can also find the index and length of the path in the string by accessing other fields of m. } Hope this helps, DigitalKing

        1 Reply Last reply
        0
        • A abhinish

          hi guys ! need some help i have to find out the file paths between string which has to be taken from User from a richtextbox the problem is there is no specified location on which the user will type the path .. it can be any where in the string for eg. user entered data something like this :

          If the above link is not visible then run the application “C:\Program Files\CasinoOnNet\Unwise.exe” and follow the instructions to uninstall the Casino on Net.

          i have to find “C:\Program Files\CasinoOnNet\Unwise.exe” in this string. these paths can be more than one and it is not necessary that they are in Quotes.. is there any way to find such paths .. any idea abhinav

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          This might look a bit cryptic, but you can also try this regex (if you don't know how it works please refer to posting #2) [A-Z]:(\\[^/<>?*"|:” ]+)(\s+[^/<>?*"|:” ]+\\|[^/<>?*"|:” ]+)*

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups