How to introduce an escape character in filepath...???

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • indona
    New Member
    • Jul 2010
    • 9

    How to introduce an escape character in filepath...???

    hi..
    i am trying to pass the file path of a text file, which i need to read, to a file object so as to read all lines of the text file. and i am selecting the file through a filedialog and i obtained the filepath and the filename using the FileName and SafefileName properties of the filedialog ...as:

    now i am facing problem in introducing the escape character to ignore the backslash punctuation while passing the filename in a string variable.

    for understanding of the problem my code is like:




    *********obtain ing the filename from filedialog property.
    filepath = dialogbox.FileN ame;
    filename = dialogbox.SafeF ileName;

    *********here i am passing the filepath obtained above into the file object to read lines from it.
    string[] lines = File.ReadAllLin es(filepath);


    consider my filepath is like:
    C:\Myfiles\abc. txt

    now i want to introduce the escape character to the filepath string to make it like:
    @"C:\Myfiles\ab c.txt"
    or
    C:\\Myfiles\\ab c.txt


    so that i can pass this filepath string to the file object as shown above.


    any idea would be very helpful..thanks a lot in advance..
  • Joseph Martell
    Recognized Expert New Member
    • Jan 2010
    • 198

    #2
    You shouldn't need to use any escape sequences. Escape sequences are for the compiler, not for the actual runtime. We use stuff like a \\ to tell the compiler to insert the appropriate character into the string in memory. The first \ character is not maintained in memory. It is just a direction to the compiler. From wikipedia:

    "There are usually two functions of escape sequences. The first is to encode a syntactic entity, such as device commands or special data which cannot be directly represented by the alphabet. The second use, referred to as character quoting, is to represent characters which cannot be typed in current context, or would have there an undesired interpretation. "

    Again, escape sequences are directions for the compiler to use certain values that either we can't type or would be difficult to interpret correctly. At runtime, such directions aren't necessary.

    Comment

    • indona
      New Member
      • Jul 2010
      • 9

      #3
      thanks a lot.. it worked..

      Comment

      Working...