DX Unified Infrastructure Management

 View Only
  • 1.  LUA - How to process special characters into a string variable for e.g PRINTF("")?

    Posted Nov 08, 2012 03:39 PM

    Example:

     

    <ID Name = "Testing123"/>

     

    i want to have the above text output into a logfile or echo on screen exactly how it appears. The problem is not the variables just the syntax to handle the parentheses.

     

    what i have is:-

     

    printf("<ID Name = ".. <???> .."/>")



  • 2.  Re: LUA - How to process special characters into a string variable for e.g PRINTF("")?
    Best Answer

    Posted Nov 08, 2012 04:14 PM

    Hi,

     

    I don't see any problem there. I assume you're getting your string "<ID Name = "Testing123"/>" from a logfile somewhere and then trying to print it, which should work just fine.

     

    if you assign the string to a variable yourself or just want to print it like that, you'll need to escape the quotation marks with \. So you''d need to do: printf("<ID Name = \"Testing123\"/>")

     

    Maybe I didn't understand your problem, if that this doesn't help, could you explain further and post your code?

     

     

     

     

     

    -jon



  • 3.  Re: LUA - How to process special characters into a string variable for e.g PRINTF("")?

    Posted Nov 08, 2012 04:58 PM

    Thats Great, just the job and good instruction, cheers



  • 4.  Re: LUA - How to process special characters into a string variable for e.g PRINTF("")?

    Posted Nov 08, 2012 05:25 PM

    The best way to do this since you probably dont want to siphon through and add escape characters everywhere is to use Single Ticks to begin and end the string. If you have double quotes in your string using single ticks to encapsulate the string is the best option in LUA. Like below works fine.

     

    printf('<ID Name = ".. <???> .."/>')