Adding new string to array?
BlitzMax Forums/BlitzMax Programming/Adding new string to array?
| ||
Hey. Im really strugeling on how to add strings to an array, or TList, or whatever. I start with an undefined sized box, and i add strings. At the end, i want to loop through these strings. I get all kinds of errors that the opreation i do is not allowed. Do i really have to define the size of an array? (And TList is pointers only, right? so that explains it doesnt take strings) |
| ||
i know i could use a custom type... but isnt there another way? type TStringArr field str:String end type |
| ||
TList takes object and string is an object. The only thing it does not take are numerics which are no objects. And an array without a size is no array, its null. You must initialize an array to be anything meaningfull. Depending on what you want to put in the array it must either be of type :string or :object, the later will need backcasting -> potentially wasted performance |
| ||
...ieSuperStrict Local MyList:TList = CreateList() For Local i:Int = 1 To 10 Local NewString:String = String(i) ListAddLast MyList,NewString Next For Local OutputString:String = EachIn MyList Print OutputString Next |
| ||
ListAddLast(lines, line) well, the above doesn't work, and im pretty sure that lines = TList line = String |
| ||
sheesh!! thanks... i forgot ... = CreateList() >_> pfff.. i need coffee! |
| ||
The above works fine, I don't post without testing. Are you using SuperStrict, and what error message are you getting? EDIT: Ah, you got it sorted! |
| ||
No its working fine :) But i was surprised to see ive een strugling all the time because i forgot to add = CreateList() :-P Thanks for your help! I now finished the thigy i was working on, and it works great. |