C# String Handling

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ryan Folstad

    #1

    C# String Handling

    Hello i have a problem with c# string handling. Hopefully someone can
    explain what im doing wrong.

    this code:
    string windowsdir = "c:\\window s";
    string installdir ="c:\\instal l";
    string path= String.Format(" {0}\\system32\\ cscript.exe {1}\\filename.v bs",
    windowsdir, installdir);

    The inspector shows:
    path = @"c:\windows\sy stem32\cscript. exe c:\install\file name.vbs"

    Problem is when i add the escape characters for \" ie:
    string path= String.Format(" {0}\\system32\\ cscript.exe
    \"{1}\\filename .vbs\"", windowsdir, installdir);

    The inspector now shows:
    path = "c:\\windows\\s ystem32\\cscrip t.exe \"c:\\install\\ filename.vbs"

    (No @ anymore and the escape sequences don't seem to be applied)

    Can anyone explain what is going on here? Do i have the escape sequence for
    a double quote wrong? Why is the addition of \" causing all escape
    sequences to not seem to be applied?

    FYI.. im using .net 1.1 on win2k3.

    Thanks,

    R


  • Frecklefoot

    #2
    Re: C# String Handling

    > Problem is when i add the escape characters for \" ie:[color=blue]
    > string path= String.Format(" {0}\\system32\\ cscript.exe
    > \"{1}\\filename .vbs\"", windowsdir, installdir);
    >
    > The inspector now shows:
    > path = "c:\\windows\\s ystem32\\cscrip t.exe \"c:\\install\\ filename.vbs"
    >
    > (No @ anymore and the escape sequences don't seem to be applied)
    >
    > Can anyone explain what is going on here? Do i have the escape sequence[/color]
    for[color=blue]
    > a double quote wrong? Why is the addition of \" causing all escape
    > sequences to not seem to be applied?[/color]

    When you say "inspector" I assume you are referring to a watch window? I
    had the same problem a bit ago. Your escape characters will still work when
    you use the string. It just shows it with the escape characters in the
    watch window so you won't confuse your \" with the double-quotes that it
    surrounds strings with. For example:

    string strFoo = "my \"quoted string\"";

    would show up as:

    strFoo = "my "quoted string""

    in the watch window if they didn't leave in the escape characters. The
    double "" can be confusing and hard to discern on some monitors. Also,
    without the escaped double-quotes, it'd be hard to tell whether the
    enclosing double-quotes were part of the string or just watch-window syntax.


    Comment

    • Ryan Folstad

      #3
      Re: C# String Handling

      yes i was referring to the watch window. And yes the presence of a \" was
      simply causing the watch window to display the string without the escape
      characters applied. Console.WriteLi ne shows the string as i expected it
      should look.

      Thanks for you help.

      R
      "Frecklefoo t" <Chris_nospam@n ospam_nsageotec h.com> wrote in message
      news:u967JkaZDH A.1640@TK2MSFTN GP10.phx.gbl...[color=blue][color=green]
      > > Problem is when i add the escape characters for \" ie:
      > > string path= String.Format(" {0}\\system32\\ cscript.exe
      > > \"{1}\\filename .vbs\"", windowsdir, installdir);
      > >
      > > The inspector now shows:
      > > path = "c:\\windows\\s ystem32\\cscrip t.exe \"c:\\install\\ filename.vbs"
      > >
      > > (No @ anymore and the escape sequences don't seem to be applied)
      > >
      > > Can anyone explain what is going on here? Do i have the escape sequence[/color]
      > for[color=green]
      > > a double quote wrong? Why is the addition of \" causing all escape
      > > sequences to not seem to be applied?[/color]
      >
      > When you say "inspector" I assume you are referring to a watch window? I
      > had the same problem a bit ago. Your escape characters will still work[/color]
      when[color=blue]
      > you use the string. It just shows it with the escape characters in the
      > watch window so you won't confuse your \" with the double-quotes that it
      > surrounds strings with. For example:
      >
      > string strFoo = "my \"quoted string\"";
      >
      > would show up as:
      >
      > strFoo = "my "quoted string""
      >
      > in the watch window if they didn't leave in the escape characters. The
      > double "" can be confusing and hard to discern on some monitors. Also,
      > without the escaped double-quotes, it'd be hard to tell whether the
      > enclosing double-quotes were part of the string or just watch-window[/color]
      syntax.[color=blue]
      >
      >[/color]


      Comment

      • Jon Skeet

        #4
        Re: C# String Handling

        Ryan Folstad <ryan@crmkb.net > wrote:

        <snip>
        [color=blue]
        > Can anyone explain what is going on here? Do i have the escape sequence for
        > a double quote wrong? Why is the addition of \" causing all escape
        > sequences to not seem to be applied?[/color]

        I suspect it's just showing it in a different format - try printing the
        value out to the console or a log file. I suspect you'll find it's
        fine, it's just the watch window behaviour.

        --
        Jon Skeet - <skeet@pobox.co m>
        Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

        If replying to the group, please do not mail me too

        Comment

        Working...