AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   String to array (https://forums.alliedmods.net/showthread.php?t=263551)

boomix 05-27-2015 18:27

String to array
 
Hello!

Very simple question, how can I make from String array?

String looks like this

weapons = "weapon_awp;weapon_smokegrenade;weapon_deagle "

I want after some kind of function to make it look like this

weapon[0] is weapon_awp
weapon[1] is weapon_smokegrenade
weapon[2] is weapon_deagle


And is it possible to count, how many weapons are in array? Thanks alot!

Darkness_ 05-27-2015 18:48

Re: String to array
 
I think this works; not totally sure though.

PHP Code:

const char[][] szWeapons = { "weapon_awp""weapon_deagle" }; 

And then just do sizeof(szWeapons) to get the size.

TnTSCS 05-27-2015 19:03

Re: String to array
 
ExplodeString is what you're looking for, I think

asherkin 05-27-2015 19:04

Re: String to array
 
If this is hard-coded, you want Darkness_'s post.
If it is coming from user input (like a convar), look at ExplodeString.

boomix 05-27-2015 19:27

Re: String to array
 
Thanks!
Thats what I was searching for - ExplodeString! :)


All times are GMT -4. The time now is 05:13.

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