-
• #2
Hi! Well, if you just want to print the string/variable, there's a special 'format' character
%v
that will do it for you (or%q
to quote it).jsiConsolePrintf("%v ", hc); // no need even for jsvAsString
Is that what you're after?
Otherwise if you need to get every character for use in your own code then
JsvStringIterator
is more sensible.There is another option which is to use the macro JSV_GET_AS_CHAR_ARRAY which will try and get a pointer to the string, will allocate memory on the stack and give you a pointer, or will just fail.
Ideally don't use that for your own code, but it's useful if you're trying to use some other code which was designed just to work on a flat memory area
-
• #3
@Gordon nice,
jsiConsolePrintf("%v ", hc);
can print the JsVar's full string, but i still can't get the full string for variable defined in c code :( , it seems like the functionjsvAsString()
only get 20 lengthJsVar *hc = jsvNewFromString('dsafsafsafdsafdsafdsafdsafdsfdsafsafsafdsfsafsafsafdsaf'); char *myStr = jsvAsString(hc); while(*myStr ){ ... myStr ++; }
-
• #4
jsvAsString
really isn't doing what you expect.As I said above, you need
JSV_GET_AS_CHAR_ARRAY
- take a look at where it's used in other places in the code - it's pretty straightforward -
• #5
it seems like the function jsvAsString() only get 20 length
maybe it was not clear from previous explanations - the string is not truncated, it is simply not stored in single piece anywhere in memory so to make it as single piece for you it must be created anew - on stack (or elsewhere) taking extra memory. So using iterator is definitely better if you iterate over it anyway, otherwise with larger strings you may overflow the stack
I want to get the full string
dsafsafsafdsafdsafdsafdsafdsfdsafsafsafdsfsafsafsafdsaf
from JsVar string as follow, but the functionjsvAsString()
seems to make the string truncated short, any good way to solve the problem? useJsvStringIterator
iterator through the JsVar?any simple way?
thax!