Thread: Reading Filename

  1. #1
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853

    Reading Filename

    I create an OpenDialox (sp?) and get the FileName property. But it is in a regular string literal, so it includes escape characters. How can read it in a verbatim string literal or put double escape // characters where there are /? As it is now it is no use.

  2. #2
    Registered User
    Join Date
    Jun 2003
    Posts
    129
    folderBrowserDialog1 myDialog = new folderBrowserDialog1();

    string myFileName = myDialog.SelectedPath;

    It does it for you...
    He who asks is a fool for five minutes, but he who does not ask remains a fool forever.

    The fool wonders, the wise man asks. - Benjamin Disraeli

    There are no foolish questions and no man becomes a fool until he has stopped asking questions. Charles Steinmetz

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    What he said. And remember: unless you are doing something extremely interesting, you don't want double backslashes and the like inside your string. I mean, when you type "C:\\windows", you don't get two backslashes inside your string, just one, which is what you need when you're dealing with a path.

  4. #4
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Quote Originally Posted by tabstop View Post
    What he said. And remember: unless you are doing something extremely interesting, you don't want double backslashes and the like inside your string. I mean, when you type "C:\\windows", you don't get two backslashes inside your string, just one, which is what you need when you're dealing with a path.
    lol, you are right. Got confused I guess *slaps himself*

  5. #5
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507
    In c# also you dont need to escape \ if you dont want to. Placing a @ before the "" will let you type a string literally as it should appear. string fileName = @"C:\data.data";

  6. #6
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Quote Originally Posted by valaris View Post
    In c# also you dont need to escape \ if you dont want to. Placing a @ before the "" will let you type a string literally as it should appear. string fileName = @"C:\data.data";
    Yeah, but can you do this?
    Code:
    string str = "\n\n";
    string s = @str;

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by C_ntua View Post
    Yeah, but can you do this?
    Code:
    string str = "\n\n";
    string s = @str;
    Well, maybe you can, but it won't result in the same thing as "\\n\\n", if that is what you wanted, I can almost guarantee that.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-11-2009, 01:49 AM
  2. Replies: 3
    Last Post: 03-05-2009, 03:14 AM
  3. Replies: 7
    Last Post: 02-02-2009, 07:27 AM
  4. Help with reading strings and opening files PLEASE
    By green2black in forum C Programming
    Replies: 8
    Last Post: 11-17-2008, 05:46 PM
  5. Reading whole file w/ ifstream
    By cboard_member in forum C++ Programming
    Replies: 5
    Last Post: 09-03-2005, 09:09 AM