Hello. I've returned to byond.
Anyway I was wondering how i could loop through a text string and get each item in order.
Example..
var/name = "Bob145"
Somehow be able to recognize "B" as the first letter, "o" as 2nd, "b", "1","4","5" and so on.
Would i be better off defining a list thats the size of the string? ie
var/list/L[sizeofstring(string)]
ID:272590
Oct 6 2008, 11:53 am
|
|
Oct 6 2008, 12:01 pm
|
|
You can use the copytext() proc to pull out particular bits of text from a string. You could then put them in a list if you wanted to. You don't need to specifically define the size of a list in BYOND: they'll grow automatically as needed.
|
In response to Jon88
|
|
Jon88 wrote:
You can use the copytext() proc to pull out particular bits of text from a string. You could then put them in a list if you wanted to. You don't need to specifically define the size of a list in BYOND: they'll grow automatically as needed. Ah, simple enough, thanks. One last question, how do i know how long the list and strings are? |
Well, depending on ASCII, you might be able to use that. I'm unsure of the orders, though! If ASCII doesn't go in alphabetical order, you could create an associative list, translate letters to numbers, and then order them with your typical sorting algorithm.
EX: text2ascii("A") //if ascii complies with alphabetical order var/list/alphabet("A"=1,"a"=1,"B"=2,"b"=2/*and so on*/) |
In response to Chibi-Gohan0
|
|
The len var =]
Also, disregard my other post, I misunderstood the question. |
In response to Jeff8500
|
|
Jeff8500 wrote:
The len var =] Right, forgot about that ^_^; its been to long. Anyway i seem to have edited my post too late. What about the string size? |
In response to Chibi-Gohan0
|
|
The length() proc. This proc can also be used on numerous other things, including lists (the len var uses less CPU, though). I suggest you read up on it.
|