creating string containing quotes (" ")

Discussion in 'Cadence' started by Roland.Fontaine, May 9, 2005.

  1. I'm trying to create a string that contains quotes and need some help.
    I've tried strcat("my \"name\" is Tom") but this leaves the \ in the
    result.
    The result I want should look like this "My "Name" is Tom", can anyone
    give me some direction on how to build this string.
     
    Roland.Fontaine, May 9, 2005
    #1
  2. printf( "%s" strcat("my \"Name\" is Svenn"))
    gives
    my "Name" is Svenn

    so it seems that your string must be correct if it is used by some other
    function accepting strings.
     
    Svenn Are Bjerkem, May 9, 2005
    #2
  3. I've tried this, but I don't believe you can assign the printf result
    to a variable to use in the future. I have also tried the sprintf
    function, but this returns the \ in the result.
     
    Roland.Fontaine, May 9, 2005
    #3
  4. It's all to do with whether you display a string using the default print
    representation of a string (which is in a form where the string could be
    used as input, and hence displays the escapes), or using printf/sprintf/fprint
    (as Svenn suggested) which shows the final intended output.

    Regards,

    Andrew.
     
    Andrew Beckett, May 9, 2005
    #4
  5. Roland.Fontaine

    S. Badel Guest

    What Svenn was trying to say is, the string actually holds what you want.
    When you do the assignment, it displays with the escaped quotes :

    a="some text \"quoted text\" some text"
    => "some text \"quoted text\" some text"

    but when you use the string, its content is correct :

    printf("%s\n" a)
    => some text "quoted text" some text

    note, you do not need strcat().

    stéphane

    NB: i believe the value of string variables is displayed quoted to distinguish them from symbol
    names and numbers. otherwise, you wouldn't be able to make a difference between 'a and "a", or
    between 1.34 and "1.34".
     
    S. Badel, May 9, 2005
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.