Raised This Month: $158 Target: $400
 39% 

How to check if A is substring of B?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
m4x
Junior Member
Join Date: Sep 2008
Old 10-03-2008 , 04:39   How to check if A is substring of B?
Reply With Quote #1

Sorry,

never done a script in this. Actualy, I need to read parameters for a function and because it is for public use, it should be flexible for variants (switching languages for teamspeak).
Like anything of "FR, fr, Fr, fra, fre, french, francais" means the same.

I would like to check, if argument used by players matches as a substring with my language strings.

decl String:ch_arg1[256];
decl String:ch_arg2[256];
ch_arg1 = "FR, fr, Fr, fra, fre, french, francais"
ch_arg2 = "DE, de, De, Ger, deu, Deutsch, german"

decl String:kanal[64];
GetCmdArg(1, kanal, sizeof(kanal));

and then something like (IN is used in eventscripts for this)

if (kanal IN ch_arg1) { .....
if (kanal IN ch_arg2) { .....


-------
Is this what I need?

Syntax: native bool:GetRegexSubString(Handle:regex, str_id, String:buffer[], maxlen);

If yes, how to use it for my problem?

THX a lot
m4x
m4x is offline
BAILOPAN
Join Date: Jan 2004
Old 10-03-2008 , 04:55   Re: How to check if A is substring of B?
Reply With Quote #2

StrContains()

Don't hardcode multilingual strings into your plugin, use the translation layer.
BAILOPAN is offline
m4x
Junior Member
Join Date: Sep 2008
Old 10-03-2008 , 07:25   Re: How to check if A is substring of B?
Reply With Quote #3

Tried this:

if (StrContains(teamspeak_charg, kanal)) {...}
if (StrContains(teamspeak_charg2, kanal)) {...}
if (StrContains(teamspeak_charg3, kanal)) {...}

every IF function is like this:
if (StrContains(teamspeak_charg4, kanal)) {
teamspeak_act_channel = teamspeak_channel;
teamspeak_act_pw = teamspeak_channelpw;
ReplyToCommand(client, "\x04[SM] TS channel %s...", teamspeak_act_channel);


----
where
teamspeak_charg1-5 are the possible strings for argument
and kanal:
decl String:kanal[64];
GetCmdArg(1, kanal, sizeof(kanal));


But it executes everything (in debug it is setting channel to all languages one after the other... until it ends in the last channel (last tested with the IF function.)

What do i have wrong?
THX
m4x is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Old 10-03-2008 , 08:17   Re: How to check if A is substring of B?
Reply With Quote #4

http://docs.sourcemod.net/api/index....ad=show&id=615

Return: -1 on failure (no match found). Any other value indicates a position in the string where the match starts.
__________________
DJ Tsunami is offline
m4x
Junior Member
Join Date: Sep 2008
Old 10-03-2008 , 09:59   Re: How to check if A is substring of B?
Reply With Quote #5

So it should be:

if (StrContains(teamspeak_charg, kanal)>=0) {...}

???
m4x is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Old 10-03-2008 , 10:21   Re: How to check if A is substring of B?
Reply With Quote #6

Yes, or != -1 instead of >= 0, whichever you prefer.
__________________
DJ Tsunami is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


Powered by vBulletin®
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Theme made by Freecode