Both sides previous revisionPrevious revisionNext revision | Previous revision |
string [2019/04/19 02:41] – korshun | string [2019/04/19 02:48] (current) – [Checking string equality] korshun |
---|
''%%""%%'' is an empty string, i.e. a valid string of length 0. It can be passed to any function and will work as expected. | ''%%""%%'' is an empty string, i.e. a valid string of length 0. It can be passed to any function and will work as expected. |
| |
===== Comparing strings for equality ===== | ===== Checking string equality ===== |
| |
<note warning>Do not use ''=='' to check if strings are equal.</note> | <note warning>Do not use ''=='' to check if strings are equal.</note> |
Operator ''=='' only checks if string **numbers** are equal. It may mostly work and then stop working randomly, or when used with a string coming from a different ACS library. | Operator ''=='' only checks if string **numbers** are equal. It may mostly work and then stop working randomly, or when used with a string coming from a different ACS library. |
| |
To check if strings are equal, you need to compare their contents. ACSUtils provides an easy to use function to check if strings are equal: | To check if strings are equal, you need to compare their contents. ACSUtils provides an easy to use function for this, which returns true if two strings are equal: |
| |
''bool StrEquals(str a, str b)'' | ''bool StrEquals(str a, str b)'' |
| |
And also a case-insensitive version: | Internally, this function calls harder to use [[zdoom>StrCmp]], but it could just as well be implemented using a combination of [[zdoom>StrLen]] and [[zdoom>GetChar]]. |
| |
| There is also a case-insensitive version: |
| |
''bool StrIEquals(str a, str b)'' | ''bool StrIEquals(str a, str b)'' |
| |
Internally, these functions call harder to use [[zdoom>StrCmp]], but they could just as well be implemented using a combination of [[zdoom>StrLen]] and [[zdoom>GetChar]]. | It's implemented using [[zdoom>StrICmp]]. |
| |
| ===== String functions ===== |
| |
| ==== StrIsEmpty ==== |
| ''bool StrIsEmpty(str s)'' |
| |
| Returns true if the string is an empty string (''%%""%%''). |
| |
| |
| |
| |