If you have a problem or need to report a bug please email : support@dsprobotics.com
There are 3 sections to this support area:
DOWNLOADS: access to product manuals, support files and drivers
HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects
USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here
NEW REGISTRATIONS - please contact us if you wish to register on the forum
Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright
something quick, to convert text to string and back
10 posts
• Page 1 of 1
something quick, to convert text to string and back
I just noticed, that green prims based procedure for converting multiline text to single-line string and back again, using standard green prims - is very slow (i.e. sluggish refresh).
But by converting text to string, I mean - changing all commas into something else (because comma sign interferes with arrays philosophy in FS), and then the end of lines into second user defined character. It's for texts longer than 255 chars in terms of single string, but that's not a problem for most FS prims.
Like this:
a,v,b,n
q,w,e
into:
a^v^b^n\q^w^e
and then back again into multiline text like above.
So - how to quickly convert texts that way using ruby, with no big lags in refreshing? (and without having too many triggers outside too). I could resign from using comma, but it's a matter of user's interface.
But by converting text to string, I mean - changing all commas into something else (because comma sign interferes with arrays philosophy in FS), and then the end of lines into second user defined character. It's for texts longer than 255 chars in terms of single string, but that's not a problem for most FS prims.
Like this:
a,v,b,n
q,w,e
into:
a^v^b^n\q^w^e
and then back again into multiline text like above.
So - how to quickly convert texts that way using ruby, with no big lags in refreshing? (and without having too many triggers outside too). I could resign from using comma, but it's a matter of user's interface.
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
Feel free to donate. Thank you for your contribution.
- tester
- Posts: 1786
- Joined: Wed Jan 18, 2012 10:52 pm
- Location: Poland, internet
Re: something quick, to convert text to string and back
I think the fastest way would be to convert string into float array (simply by converting the format - bits untouched!). Convert the float array to mem - the mem readout to assembly block and from there to analyzer, form analyzer to Float array to string array converter (again, leaving the bit information untouched - only changing the format).
The assembly block would read the input and comparing it with bit pattern of comma and newline, if detected replace output with bit pattern of desired character.
However you'll have to find out how to change string into float array and back without affecting the actual stored information bitwise...
The assembly block would read the input and comparing it with bit pattern of comma and newline, if detected replace output with bit pattern of desired character.
However you'll have to find out how to change string into float array and back without affecting the actual stored information bitwise...
- KG_is_back
- Posts: 1196
- Joined: Tue Oct 22, 2013 5:43 pm
- Location: Slovakia
Re: something quick, to convert text to string and back
This is just a text within app; multiple blocks (dynamic amount) of viewable text (associated with some other data in the background). Rather ruby should do this job quickly, nothing else.
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
Feel free to donate. Thank you for your contribution.
- tester
- Posts: 1786
- Joined: Wed Jan 18, 2012 10:52 pm
- Location: Poland, internet
Re: something quick, to convert text to string and back
you can use the methode ".tr" from the string class, depending on what you are doing with it you can use the destructive or nondestructive one
http://ruby-doc.org/core-2.0.0/String.html#method-i-tr
like
http://ruby-doc.org/core-2.0.0/String.html#method-i-tr
like
- Code: Select all
@in.tr!(",","^")
-
Nubeat7 - Posts: 1347
- Joined: Sat Apr 14, 2012 9:59 am
- Location: Vienna
Re: something quick, to convert text to string and back
Which one will be faster?
What is the practical difference between destructive and non-destructive? A some sort of passthrough like additional "dummy" connectors in FS?
//edit: works definately faster than green prims, on the fly, thanks!
BTW, and how to create multiple conversions within one code? Just copy lines changing chars to change, or there is a faster way?
What is the practical difference between destructive and non-destructive? A some sort of passthrough like additional "dummy" connectors in FS?
//edit: works definately faster than green prims, on the fly, thanks!
BTW, and how to create multiple conversions within one code? Just copy lines changing chars to change, or there is a faster way?
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
Feel free to donate. Thank you for your contribution.
- tester
- Posts: 1786
- Joined: Wed Jan 18, 2012 10:52 pm
- Location: Poland, internet
Re: something quick, to convert text to string and back
Okay, I have a small problem.
It returns output only if input has commas, but empty, when it's without comma.
It returns output only if input has commas, but empty, when it's without comma.
- Attachments
-
- small problem.fsm
- (334 Bytes) Downloaded 841 times
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
Feel free to donate. Thank you for your contribution.
- tester
- Posts: 1786
- Joined: Wed Jan 18, 2012 10:52 pm
- Location: Poland, internet
Re: something quick, to convert text to string and back
hmm interesting, i dont know why but use it without "!" then it works right!
the differnce between destructive and nondestructive is that the original element stays original and a modified copy is returned when using a nondestructive (without "!") methode while when using the destructive version the original element gets modified like
a = 1,2,3,4
output 0, a.tr (",","^") => 1^2^3^4 returns the modified copy
output 1, a => 1,2,3,4 a by itself is not touched
while using destructive version
output 0, a.tr! (",","^") => 1^2^3^4 returns the modified original
output 1, a => 1^2^3^4 the original is modified now!
for multiple changes you can take the same methode, just say what you want to change:
q=aaabbbcccddd
q.tr("a,b","x,y") => xxxyyycccddd
the differnce between destructive and nondestructive is that the original element stays original and a modified copy is returned when using a nondestructive (without "!") methode while when using the destructive version the original element gets modified like
a = 1,2,3,4
output 0, a.tr (",","^") => 1^2^3^4 returns the modified copy
output 1, a => 1,2,3,4 a by itself is not touched
while using destructive version
output 0, a.tr! (",","^") => 1^2^3^4 returns the modified original
output 1, a => 1^2^3^4 the original is modified now!
for multiple changes you can take the same methode, just say what you want to change:
q=aaabbbcccddd
q.tr("a,b","x,y") => xxxyyycccddd
Last edited by Nubeat7 on Sat Oct 26, 2013 11:43 pm, edited 1 time in total.
-
Nubeat7 - Posts: 1347
- Joined: Sat Apr 14, 2012 9:59 am
- Location: Vienna
Re: something quick, to convert text to string and back
Yes, I just figured out, that without "!" works for some reason.
Maybe this is something like "return nothing if nothing changed"?
For me, the difference between destructive and non-destructive looks like simple additional "passthrough". I guess this is because it's more useful in different environments, that don't work like FS. Destructive shoud then be faster, and less memory usage (no copy of input) then.
Okay, and how to combine multiple character changes (in single text; like comma and new line) in one ruby code? I mean without cascading the module in FS.
//edit: you were faster.
Maybe this is something like "return nothing if nothing changed"?
For me, the difference between destructive and non-destructive looks like simple additional "passthrough". I guess this is because it's more useful in different environments, that don't work like FS. Destructive shoud then be faster, and less memory usage (no copy of input) then.
Okay, and how to combine multiple character changes (in single text; like comma and new line) in one ruby code? I mean without cascading the module in FS.
//edit: you were faster.
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
Feel free to donate. Thank you for your contribution.
- tester
- Posts: 1786
- Joined: Wed Jan 18, 2012 10:52 pm
- Location: Poland, internet
Re: something quick, to convert text to string and back
tester wrote:Yes, I just figured out, that without "!" works for some reason.
Maybe this is something like "return nothing if nothing changed"?
For me, the difference between destructive and non-destructive looks like simple additional "passthrough". I guess this is because it's more useful in different environments, that don't work like FS. Destructive shoud then be faster, and less memory usage (no copy of input) then.
Okay, and how to combine multiple character changes (in single text; like comma and new line) in one ruby code? I mean without cascading the module in FS.
just edited the last answer for multiple changes... you was too fast!
the destructive version dont work because it returns nil if there was nothing changed! (info: ruby doc)
-
Nubeat7 - Posts: 1347
- Joined: Sat Apr 14, 2012 9:59 am
- Location: Vienna
Re: something quick, to convert text to string and back
Yes, I just noticed it. So it looks that the destructive method is like passthrough plus some sort of boolean indicator (result or nil).
Okay, thanks for help.
Okay, thanks for help.
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
Feel free to donate. Thank you for your contribution.
- tester
- Posts: 1786
- Joined: Wed Jan 18, 2012 10:52 pm
- Location: Poland, internet
10 posts
• Page 1 of 1
Who is online
Users browsing this forum: Majestic-12 [Bot] and 39 guests