Raised This Month: $51 Target: $400
 12% 

Empty string


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 12-03-2014 , 22:08   Empty string
Reply With Quote #1

Ciao guys,

yes, it's me again... I got a two, kind of lame questions...

1) What is the best way, how to determine if string is empty?
PHP Code:
// is empty option 1
if (StrEqual(sMyString""))

// is empty option 2
if (strlen(sMyString) == 0)

// is empty option 3
if (sMyString[0] == EOS
2) And how to make string empty properly?
PHP Code:
// make empty option 1
strcopy(sMyStringsizeof(sMyString), "");

// make empty option 2
sMyString[0] = EOS

Last edited by KissLick; 12-04-2014 at 09:44.
KissLick is offline
Leonardo
Veteran Member
Join Date: Feb 2010
Location: 90's
Old 12-03-2014 , 23:19   Re: Empty string
Reply With Quote #2

PHP Code:
strcopy(sMyStringsizeof(sMyString"")); // typo
strcopy(sMyStringsizeof(sMyString), ""); 
where did you get that EOS ?

setting first cell to a zero-terminatin character is the fastest way.

my guess is, strcopy would clean the whole string.

you might also want to trim strings before checking.
__________________
Leonardo is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 12-04-2014 , 09:47   Re: Empty string
Reply With Quote #3

Quote:
Originally Posted by Leonardo View Post
PHP Code:
strcopy(sMyStringsizeof(sMyString"")); // typo
strcopy(sMyStringsizeof(sMyString), ""); 
Thx.

Quote:
Originally Posted by Leonardo View Post
where did you get that EOS ?
PHP Code:
EOF end of file // not sure if it works in sp
EOL end of line // not sure if it works in sp
EOS end of stream // same as '\0' in sp 

Last edited by KissLick; 12-04-2014 at 09:47.
KissLick is offline
Root_
Veteran Member
Join Date: Jan 2012
Location: ryssland
Old 12-04-2014 , 10:13   Re: Empty string
Reply With Quote #4

It depends on your purpose... personally I use
Code:
if (!sMyString[0])
which means string is empty.

And again to 'clean up' string you can use this
Code:
sMyString[0] = '\0'

This method will not be available with new syntax, but that's none of my business.
__________________


dodsplugins.com - Plugins and Resources for Day of Defeat
http://twitch.tv/zadroot
Root_ is offline
Leonardo
Veteran Member
Join Date: Feb 2010
Location: 90's
Old 12-04-2014 , 11:20   Re: Empty string
Reply With Quote #5

Quote:
Originally Posted by KissLick View Post
PHP Code:
EOF end of file // not sure if it works in sp
EOL end of line // not sure if it works in sp
EOS end of stream // same as '\0' in sp 
Where they're defined at?

Quote:
Originally Posted by Root_ View Post
This method will not be available with new syntax, but that's none of my business.
wai-wait whoa hold on what?!
__________________
Leonardo is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 12-04-2014 , 13:27   Re: Empty string
Reply With Quote #6

Quote:
Originally Posted by Leonardo View Post
Where they're defined at?
I didn't find anything in the includes, but I found this.

EDIT: And EOL should by according to OS, linux = LF, win = CRLF

Last edited by KissLick; 12-04-2014 at 13:29.
KissLick is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 12-04-2014 , 15:04   Re: Empty string
Reply With Quote #7

Just check if he cell is '\0' or whatever delim you are using
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 12-04-2014 , 16:46   Re: Empty string
Reply With Quote #8

Quote:
Originally Posted by KissLick View Post
I didn't find anything in the includes, but I found this.
Please never, ever use that constant in a SourceMod plugin.

Quote:
Originally Posted by Root_ View Post
This method will not be available with new syntax, but that's none of my business.
What makes you think that? The whole point of the type rename is to clarify them as being char arrays rather than first-class strings.
__________________
asherkin is offline
Reply



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 10:40.


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