[Closed] removing quotes from text output
hi all,
i know my question is stupid but i couldn’t find any answer in the maxscript help after hours of research…
i made a script that outputs a text file; everything is ok excepted the fact that i have quotes around every string printed. it’s very frustrating.
I use the “print <string> to:<filestream>” function.
any help would be greatly appreciated.
Dont’t use Print, use Format instead.
format “%
” <string or value> to:<filestream>
ah, thanks a lot, i knew it was stupid, i feel better now.
I’m still wondering why there’s nothing in the reference about those quotes. Why are they there with print?:shrug:
A String Value in MAXScript always has the quotes.
The Print method always outputs a string as is, including the quotes.
If you Print another value, like an integer, there will be no quotes unless you convert the value to string.
This is because, as the Reference explains in the “Value Common Properties, Operators and Methods” topic, all values written out with print will be directly readable by readValue() and readExpression(). In order to know that a string is being read back, the string value must be output with its quotes. If that were not the case, readExpression() would have tried to convert the string to a user variable and would have returned undefined if that variable did not exist, or even error out.
Format on the other hand uses a formatting string to define what will be output and does not care about readValue() and readExpression(). It never outputs the quotes of a String value unless the formatting string (first argument of the format() method) explicitly specifies them. Format is intended for more controlled output and should be used when the format (pun intended) of the output matters.
(
a = "Test" --this is a string and has quotes
b = 10 --this is an integer and does not have quotes
f = createFile "c:\ emp\\print.txt" --create a temp. file for testing
print a to:f --print the string to the file
print b to:f --print the integer to the file
print (b as string) to:f --print the integer converted to string to the file
format "%
" a to:f --now format the string to the file
format "%
" b to:f --format the integer to the file
format "%
" (b as string) to:f --format the integer as string to the file
format "\"%\"
" a to:f --format the string to the file with explicit quotes
close f --close the file
edit "c:\ emp\\print.txt" --open to see it
)
Result:
"Test" --printed string with quotes
10 --printed integer - no quites
"10" --printed integer as string - with quotes
Test --formatted string - no quotes
10 --formatted integer - no quotes
10 --formatted integer as string - no quotes
"Test" --formatted string with explicit quotes
thanks a lot for those explanations!
I understand now why it is like that, and that’s better that just knowing how to get desired result.
I really appreciate your help, thx.
Bobo’s answer is, as always, perfect for your purposes, but if you just want to delete the quotes, you can also use trimLeft (and trimRight) <string> “””