Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • double quotation marks or single quotation marks

    Whether it is using double quotation marks or single quotation marks, an error will be reported. What should I do in this case?
    Code:
    dis wordcount(`"apple"  `iphone"')
    dis wordcount("apple"  `iphone")

  • #2
    I guess the real question is what you are trying to do here and where these strings are coming from. Of course they produce error message because in both examples the quotes are unbalanced. `" has to be balanced by "'. " has to be balanced by ". And ` has to be balanced by '. In your first example
    Code:
    dis wordcount(`"apple" `iphone"')
    the outer `" and "' balance each other (in red). But the inner " and ` cannot balance each other and have nothing else to balance them.

    In your second example
    Code:
    dis wordcount("apple" `iphone")
    the double quotes around apple (in red) balance each other. But the ` preceding iphone has no ' to balance it, and the final " after iphone has nothing before to balance it either. Again, it appears you are trying to balance a " with a `, and that will never work.

    But again, I wonder where these strings are even coming from. How did they arise in your code?

    Comment


    • #3
      I also wonder what Clyde asked, and I also wonder why you keep on adding quotation marks and do not just do:

      Code:
      . dis wordcount("apple iphone")
      2

      Comment


      • #4
        Something more can be said here because OP does not fundamentally understand or differentiate the different types of quotes. Please see -help quotes- for a detailed discussion. In essence there are 3 types of quotes. The left and right single quote (` and ') have meaning only in signaling that a macro variable or function is intended; this appears to not be the case here. The second are traditional double quotes (""), which are used to wrap strings/textual information. However, when your strings may themselves include double quote marks, then you must use compound double quotes (`" and "'). The latter two are equivalent when the data do not contain double quote marks.

        Comment


        • #5
          Dear Clyde
          thank you very much for your detailed and comprehensive explanation.
          My purpose is to display a string, which contains apple` "iphone. But I don’t know how to do it. The following two methods will report errors.
          Code:
          dis   "apple` "iphone"
          dis  `"apple` "iphone"'

          Comment


          • #6
            Originally posted by Song Bolin View Post
            Dear Clyde
            thank you very much for your detailed and comprehensive explanation.
            My purpose is to display a string, which contains apple` "iphone. But I don’t know how to do it. The following two methods will report errors.
            Code:
            dis "apple` "iphone"
            dis `"apple` "iphone"'
            In this case, you need to use compound double quotes around the whole string, and then escape the single left quote using a backslash to indicate that you really just want that single quote character and not a macro.

            Code:
            dis   `"apple\` "iphone"'
            However, it doesn't make good sense to have these unbalanced quotation marks (above in red), so you should give some thought as to what your end goal really is.

            Comment


            • #7
              Originally posted by Leonardo Guizzetti View Post

              In this case, you need to use compound double quotes around the whole string, and then escape the single left quote using a backslash to indicate that you really just want that single quote character and not a macro.

              Code:
              dis `"apple\` "iphone"'
              However, it doesn't make good sense to have these unbalanced quotation marks (above in red), so you should give some thought as to what your end goal really is.
              Thanks Leonardo. Use a backslash to escape the left single quotation mark. The operation meets my needs.

              Comment

              Working...
              X