string startswith or endswith a double quote?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • zacks@construction-imaging.com

    string startswith or endswith a double quote?

    I need to check the current value of a string value to see if it
    either starts with or ends with a double quote character, as in
    "123" (where the quotes are actual contens of the string). I thought a
    quotation character inside of a string is specified with two double
    quote characters. But when I code something like:

    string myString;

    if (myString.Start sWith(""""))
    {
    }

    A syntax error of "Expecting )" is given.

    How can I do this in C#.NET?

  • zacks@construction-imaging.com

    #2
    Re: string startswith or endswith a double quote?

    On Sep 15, 2:51 pm, za...@construct ion-imaging.com wrote:
    I need to check the current value of a string value to see if it
    either starts with or ends with a double quote character, as in
    "123" (where the quotes are actual contens of the string). I thought a
    quotation character inside of a string is specified with two double
    quote characters. But when I code something like:
    >
    string myString;
    >
    if (myString.Start sWith(""""))
    {
    >
    }
    >
    A syntax error of "Expecting )" is given.
    >
    How can I do this in C#.NET?
    Sorry for the wasted bandwidth, I figured this out minutes after
    posting this. I had forgotten how C# likes to escape special
    characters. It is done with:

    string myString;

    myString = "\"123\"";
    if (myString.Start sWith("\""))
    MessageBox.Show ("YES");

    Comment

    • Dave Anson

      #3
      Re: string startswith or endswith a double quote?

      zacks@construct ion-imaging.com wrote in news:1189882300 .460415.152380
      @n39g2000hsh.go oglegroups.com:
      I need to check the current value of a string value to see if it
      either starts with or ends with a double quote character, as in
      "123" (where the quotes are actual contens of the string). I thought a
      quotation character inside of a string is specified with two double
      quote characters. But when I code something like:
      >
      string myString;
      >
      if (myString.Start sWith(""""))
      {
      }
      >
      A syntax error of "Expecting )" is given.
      >
      How can I do this in C#.NET?
      >
      >

      if (myString.Start sWith("\""))
      {
      }


      --
      Regards
      JTC ^..^

      Comment

      • =?ISO-8859-1?Q?G=F6ran_Andersson?=

        #4
        Re: string startswith or endswith a double quote?

        zacks@construct ion-imaging.com wrote:
        On Sep 15, 2:51 pm, za...@construct ion-imaging.com wrote:
        >I need to check the current value of a string value to see if it
        >either starts with or ends with a double quote character, as in
        >"123" (where the quotes are actual contens of the string). I thought a
        >quotation character inside of a string is specified with two double
        >quote characters. But when I code something like:
        >>
        >string myString;
        >>
        >if (myString.Start sWith(""""))
        >{
        >>
        >}
        >>
        >A syntax error of "Expecting )" is given.
        >>
        >How can I do this in C#.NET?
        >
        Sorry for the wasted bandwidth, I figured this out minutes after
        posting this. I had forgotten how C# likes to escape special
        characters. It is done with:
        >
        string myString;
        >
        myString = "\"123\"";
        if (myString.Start sWith("\""))
        MessageBox.Show ("YES");
        >
        Tip: If you know for certain that the length of the string is always at
        least one, you can just check the first character:

        if (myString[0] == '"')

        --
        Göran Andersson
        _____
        Göran Anderssons privata hemsida.

        Comment

        • Peter Duniho

          #5
          Re: string startswith or endswith a double quote?

          Göran Andersson wrote:
          Tip: If you know for certain that the length of the string is always at
          least one, you can just check the first character:
          >
          if (myString[0] == '"')
          For that matter, if the length is also always at least one:

          if (myString[myString.Length - 1] == '"')

          That said, since you could also do the equivalent using the Substring()
          method, even for search strings larger than a single character, it seems
          obvious to me that the main reason StartsWith() and EndsWidth() even
          exist is more for convenience and readability than anything else.

          And IMHO, that motivation for using those methods doesn't go away for
          strings that are always at least one character long. :)

          Pete

          Comment

          Working...