Strings functions in algodoo
11 posts • Page 1 of 1
Strings functions in algodoo
I've made some basic functions to use text strings in algodoo.
V2 :
V1 :
String format : (All my functions use this format)
example :
V2 Changes :
V1 :
Functions list is in the description of the scene but I put them here too for a better lisibility :
Note :
Fast mean that the length of the string will not affect the speed of the function.
Slow mean that bigger will be the string, slower will be the function.
The limit of strings about 400 char is due to the for function used in this script (I used the one you can get at viewtopic.php?f=13&t=411), if you have a "for" function wich handle bigger numbers (and if possible wich is faster) or other string functions ideas tell me.
If you found some bugs, I'll try to fix them.
My text to algodoo string tool : Here
Known bugs(s) :
This scene can be used as phunlet and should work in phun.
Example scenes:
(I'll add another one at another time)
V2 :
V1 :
String format : (All my functions use this format)
- Code: Select all
[string Length, string elements]
example :
- Code: Select all
str = [11,["H","e","l","l","o"," ","W","o","r","l","d"]]
V2 Changes :
- For all functions, String length limit is now over 10 000 (Thanks to KarateBrot for the link and immibis for the for2 function).
- subStrToText([str], [start], [length]) Return the chars wich are in [str] between start to start+length into classic text.
Return type : Text
Speed : Slow
String length limit : over 10 000 in V2
Example :- Code: Select all
Scene.my.str = [11,["H","e","l","l","o"," ","W","o","r","l","d"]];
Scene.my.subStrToText(Scene.my.str, 0, 5);
- Code: Select all
Hello
- You can install this lib on your HDD by downloading this file : stringFunctions2.cfg (open the file with à text editor to know how to install it)
- If you installed this lib on your HDD you can also install this file to get infix operators : stringFunctions2infix.cfg (open the file with à text editor to know how to install it)
Infix operators are :- Code: Select all
#str1+str2 //strCat
str::length //strLen
str::toText //strToText
str::subStr|start|length| //subStr
str::addChar|char|place| //addChar
str::subChar|place| //subChar
str::getChar|pos| //getChar
str::setChar|char|pos| //setChar
str::subStrToText|start|length| //subStrToText
str|pos| (same as str::getChar|pos| but shorter) //getChar
"str"|pos|=char (same as str::setChar|char|pos| but shorter (this infix operator return no value, str is directly modified)) //a modified setChar function
(return values of all infix operators (excluding "str"|pos|=char ) are the sames as Scene.my.* functions)
V1 :
Functions list is in the description of the scene but I put them here too for a better lisibility :
- strCat([str1], [str2]) Concatenate [str1] with [str2].
Return type : String
Speed : Fast
String length limit : No limit
Example :- Code: Select all
Scene.my.str1 = [6,["H","e","l","l","o"," "]];
Scene.my.str2 = [5,["W","o","r","l","d"]];
Scene.my.strCat(Scene.my.str1,Scene.my.str2);
- Code: Select all
[11,["H","e","l","l","o"," ","W","o","r","l","d"]]
- strLen([str]) Return the length of [str].
Return type : Integer
Speed : Fast
String length limit : No limit
Example :- Code: Select all
Scene.my.str = [11,["H","e","l","l","o"," ","W","o","r","l","d"]];
Scene.my.strLen(Scene.my.str);
- Code: Select all
11
- strToText([str]) Convert [str] into classic text.
Return type : Text
Speed : Slow
String length limit : About 400 characters (over 10 000 in V2)
Example :- Code: Select all
Scene.my.str = [11,["H","e","l","l","o"," ","W","o","r","l","d"]];
Scene.my.strToText(Scene.my.str);
- Code: Select all
Hello World
- subStr([str], [start], [length]) Return the chars wich are in [str] between start to start+length.
Return type : String
Speed : Slow
String length limit : [length] is about 400 (over 10 000 in V2)
Example :- Code: Select all
Scene.my.str = [11,["H","e","l","l","o"," ","W","o","r","l","d"]];
Scene.my.subStr(Scene.my.str, 0, 5);
- Code: Select all
[5,["H","e","l","l","o"]]
- addChar([str], [char], [place]) Return [str] with [char] inserted at position [place].
Return type : String
Speed : Fast for [place] = 0 and [place] = Scene.my.strLen([str]) slow for others places
String length limit : No limit for [place] = 0 and [place] = Scene.my.strLen([str]), about 400 chars for others places (over 10 000 in V2)
Example :- Code: Select all
Scene.my.str = [10,["H","e","l","l"," ","W","o","r","l","d"]];
Scene.my.addChar(Scene.my.str, "o", 4);
- Code: Select all
[11,["H","e","l","l","o"," ","W","o","r","l","d"]]
- charToStr([char]) Convert [char] into a string of length = 1.
Return type : String
Speed : Fast
String length limit : No limit
Example :- Code: Select all
Scene.my.charToStr("o");
- Code: Select all
[1,["o"]]
- subChar([str], [place]) Return [str] without the char at position [place].
Return type : String
Speed : Slow
String length limit : About 400 characters (over 10 000 in V2)
Example :- Code: Select all
Scene.my.str = [11,["H","e","l","l","o"," ","W","o","r","l","d"]];
Scene.my.subChar(Scene.my.str, 4);
- Code: Select all
[10,["H","e","l","l"," ","W","o","r","l","d"]]
- getChar([str], [pos]) Return the char wich is at position [pos] in [str].
Return type : Text
Speed : Fast
String length limit : No limit
Example :- Code: Select all
Scene.my.str = [11,["H","e","l","l","o"," ","W","o","r","l","d"]];
Scene.my.getChar(Scene.my.str, 1);
- Code: Select all
e
- setChar([str], [char], [pos]) Replace the char at position [pos] in [str] by [char].
Return type : String
Speed : Slow
String length limit : About 400 characters (over 10 000 in V2)
Example :- Code: Select all
Scene.my.str = [11,["H","e","l","l","o","o","W","o","r","l","d"]];
Scene.my.setChar(Scene.my.str, " ", 5);
- Code: Select all
[11,["H","e","l","l","o"," ","W","o","r","l","d"]]
Note :
Fast mean that the length of the string will not affect the speed of the function.
Slow mean that bigger will be the string, slower will be the function.
The limit of strings about 400 char is due to the for function used in this script (I used the one you can get at viewtopic.php?f=13&t=411), if you have a "for" function wich handle bigger numbers (and if possible wich is faster) or other string functions ideas tell me.
If you found some bugs, I'll try to fix them.
My text to algodoo string tool : Here
Known bugs(s) :
- You can't use the chars ], ) and } alone (You can try to type "]", ")", "}" in console, you'll get an error)
This scene can be used as phunlet and should work in phun.
Example scenes:
(I'll add another one at another time)
Last edited by REMqb on Thu Sep 09, 2010 5:35 pm, edited 4 times in total.
- REMqb
- Posts: 15
- Joined: Wed Dec 30, 2009 7:51 pm
- Location: France
Re: Strings functions in algodoo
Incredibly long for-function:
http://www.algodoo.com/forum/viewtopic.php?f=13&t=371&start=0#p8695
I tested it up to 5000 loops. Because it took a lot of time I didn't go further.
http://www.algodoo.com/forum/viewtopic.php?f=13&t=371&start=0#p8695
I tested it up to 5000 loops. Because it took a lot of time I didn't go further.
-
KarateBrot - Posts: 825
- Joined: Mon Aug 31, 2009 7:32 pm
- Location: Germany
Re: Strings functions in algodoo
Thank you but I get warnings with it and this for functions is very slow .
(I get warnings which say "bad index in list")
(I get warnings which say "bad index in list")
- REMqb
- Posts: 15
- Joined: Wed Dec 30, 2009 7:51 pm
- Location: France
Re: Strings functions in algodoo
did you use the correct command? ( scene.my.for2(loops, (whatever)=>{ } ) )
yeah it's a bit slow but if you really need more than 400 loops it's cool^^
yeah it's a bit slow but if you really need more than 400 loops it's cool^^
-
KarateBrot - Posts: 825
- Joined: Mon Aug 31, 2009 7:32 pm
- Location: Germany
Re: Strings functions in algodoo
Yes I used the correct command :/
- REMqb
- Posts: 15
- Joined: Wed Dec 30, 2009 7:51 pm
- Location: France
Re: Strings functions in algodoo
hmm i dunno. i never get warnings. maybe something was wrong with your script? maybe you made a typing mistake.
-
KarateBrot - Posts: 825
- Joined: Mon Aug 31, 2009 7:32 pm
- Location: Germany
Re: Strings functions in algodoo
I found the problem ^^what(min) in for2_internal must be replaced by what(Math.toInt(min)) because min is a float number and you can't use float numbers for lists.
- Code: Select all
list(1.0) : error
list(1) : work
- REMqb
- Posts: 15
- Joined: Wed Dec 30, 2009 7:51 pm
- Location: France
Re: Strings functions in algodoo
and how does it happen that there will be a float number? i never got this error
-
KarateBrot - Posts: 825
- Joined: Mon Aug 31, 2009 7:32 pm
- Location: Germany
Re: Strings functions in algodoo
I don't know but with that change it works.
- REMqb
- Posts: 15
- Joined: Wed Dec 30, 2009 7:51 pm
- Location: France
Re: Strings functions in algodoo
Updated to V2 :
read the first post for details
- added 1 function
- now handle over strings with a length over 10 000
- infix operators if you install it on your HDD
read the first post for details
- REMqb
- Posts: 15
- Joined: Wed Dec 30, 2009 7:51 pm
- Location: France
Re: Strings functions in algodoo
i think this is like the first 3rd party library for thyme, historic!
- Mr_Stabby
- Posts: 155
- Joined: Wed Dec 16, 2009 12:16 am
11 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 5 guests