AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Concatenation of strings (putting two strings together)? (https://forums.alliedmods.net/showthread.php?t=89823)

OldWolf 04-11-2009 02:23

Concatenation of strings (putting two strings together)?
 
Howdy all,

I'm sure this is a no brainer, but I'm stumped:

I'm looping through a folder of maps. As each map is verified to be a legit map, I want to add it to a string in the following format (it's SQL if you're curious):

Code:

[some sql code will be here starting the string off, but it's not relevant]
('de_dust', 'foo', 'bar'),
('de_dust2', 'foo2', 'bar'),
('some_other_map', 'foo2', 'bar'),
('more_maps', 'foo2', 'bar'),
('zm_mansion', 'fooiest', 'bariest')

[The new lines aren't really in there, that was just to make it easier to see what I meant]

So where I stand right now is that I have the name of the map in a variable, and I can use the format function to put that name into the format of ('map_name', 'extra_value1', 'extra_value2')

Now, how do I add them to the existing list so they become one long string of value sets like that, with each separated by a comma (the last one shouldn't have a comma after it)?


Thank you!!!

Emp` 04-11-2009 02:31

Re: Concatenation of strings (putting two strings together)?
 
Code:

new string[2001], iLen;
iLen += copy(string[iLen], (2001-iLen),                "Stuff");
iLen += formatex(string[iLen], (2001-iLen),        "Heres more stuff %s", szMoreStuff);

Code:

new list[2001], iLen;
iLen += formatex(list[iLen], (2001-iLen),                "'%s'", first_item);
for( new i; i<item_num; i++ )
        iLen += formatex(list[iLen], (2001-iLen),        ", '%s'", other_items[i]);


OldWolf 04-11-2009 03:08

Re: Concatenation of strings (putting two strings together)?
 
Hey, that's just what I wanted!

My only problem:
I'm not sure what the length of the whole string might be after each data set has been added, since there's no limit to how many maps a server might have. Is there a way to make it open ended, or should I just set it to a really large number?

Thanks for getting back to me so quickly!

Emp` 04-11-2009 04:06

Re: Concatenation of strings (putting two strings together)?
 
Could either use a large array, or you could use cellarray. I don't have much experience with it, and I don't think there is a tutorial on it, so you would have to look at other plugins that use it.

OldWolf 04-12-2009 23:30

Re: Concatenation of strings (putting two strings together)?
 
Large array it is. :P

Hehe... I'm not lazy, I'm just really not sure what I'd be looking for. I can always upgrade it later when I learn more.. I'll look into it when I'm a little more experienced.

Thanks for your help! :)


All times are GMT -4. The time now is 02:24.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.