Double Quotes in [sprintf] produces unwanted backslash character
Hi all,
I need to generate a string with double quotes. What I've gotten so far is that I need to use a triple backslash before the double quote in the [sprintf] object, e.g. {test this \\\"%s\\\"}, but [sprintf] outputs a backslash before the double quotes, e.g. {test this \"string\"}.
I'm using this to format a command string to send over a network. The receiver will not understand the backslash. Any ideas how to generate the proper string?
Max doesn't have a defined way to handle strings like other languages - it was never designed to! On top of that, you have the problem that double quotes and backslash take on special meanings depending on where you use them.
This worked for another user but only for creating lines of text in a text object - send the output to a message object and it will do something totally different:

This also works in some situations but not others, as some Max objects will strip the quotes off again:

sprintf uses a formatting syntax derived from C++ (that does handle strings) and whilst it can be extremely useful in many situations, it can play havoc with Max as far as strings, symbols and special characters are concerned.
Incidentally, I think the questions that many will ask is how you intend to transmit these messages from Max, what their purpose is and why the quotes are necessary in the first place?
I'm sending them over TCP using the sadam package, and they're command strings for a third-party device. The quotes are specified for string arguments in the manufacturer's command language. I have to be a bit vague, because I'm not at liberty to disclose specifics about said command language.
Once the command string is formatted, however, it's converted to ascii digits using [atoi] and then into hex using [sadam.toBytes]. All of that is working great for all the commands that take integer and float arguments.
Currently I'm seeing if javascript might be the way to go, but I'm having just as much trouble getting a straight forward answer on how to format strings in JS, and then I have to contend with the double quotes around the entire command string. Another option may be to append the string arguments once the rest of the command has been converted to ascii digits, but I'd like to avoid this if there's a more elegant solution.
Ok, so if you have converted the string into a list of integers with atoi, how about just using prepend and append with the ASCII code (before sadam.toBytes) or hex code (after sadam.toBytes) for the double quotes character just before you send it?

Yeah that's where I'm at now, I just wanted it to be able to follow the same logic as all the other commands, but at the end of the day if it works, it works.
Thanks!
Yes, unfortunately that’s sometimes the only way to think about it with Max!