Splitting Up Strings?


Quiest

I like turtles!
Joined
Sep 2, 2004
Messages
3,411
Age
40
Location
Dteuschland ;)
Is there any possible way to do this?

Let`s say I have the string variable sdf with the value "text", and I want to change the var from sdf="text" to sdf="x", meaning it should just delete all other letters except the third, like "blabla" would result into "a" for example.

Or much easier would be to assign a string to an array so that array[0]="t", array[1]="e", array[2]="x" and array[3]="t".

Another thing that would help me is to just roll or shift the letters in the string so "text" would result in "extt" or "ext", then "xtte" or "xt" after the next shift, then "ttex" or "t", and so on.


Sorry, it`s hard for me to explain that, please help!
 
Hmmm, I don't know if Fenix, but in C the string lib has mechanisms for manipulating strings, such as sdf.find(x) would retrun a 2. Maybe Fenix has built in functions for this.

I don't see how you could go wrong with an char array, and just loop through it and manipulate it as needed. Fenix is an odd, maybe oversimplified language. Pretty cool really.
 
Ah, just browsed the spanish help file included with Flamebird2 a bit, and although I can`t read a word spanish, I found the right command to do this.

Case solved.
 
Yes it is.

So just an example usage:

string text1="text";
string text2;

text2=substr(text1,1,1); would result in text2="e"
text2=substr(text1,0,3); would result in text2="tex"
text2=substr(text1,2,1); would result in text2="x"

start is the index number of the trings letters, first letter is 0, second is 1, etc. and end defines how many letters should be kept after that letter.

The naming of the parameters is not that obvious...
 
Ok, I haven't used it for a while, but I thought it was the opposite of the PHP function, which has the substring length as third parameter(the opposite being the place of the last character). You're surely right then, I stand corrected :). And then for *EXTREME* clarity:

substr(STRING str, INT start, INT length)
 
Back
Top