mirror of
https://github.com/EpochModTeam/DayZ-Epoch.git
synced 2026-02-25 17:31:36 +03:00
better fn_string by KK
This commit is contained in:
@@ -1,28 +1,31 @@
|
|||||||
//Kilzone_Kid's megafast inString function
|
/*
|
||||||
//caseinsensitive
|
Author: Killzone_Kid
|
||||||
//params [needle,haystack]
|
|
||||||
private["_needle","_haystack","_found","_haystackArr","_haystackLen","_needleLen","_hayArr"];
|
Description:
|
||||||
scopeName "main";
|
Find a string within a string (case insensitive)
|
||||||
_needle = _this select 0;
|
|
||||||
_haystack = _this select 1;
|
Parameter(s):
|
||||||
_haystackArr = toArray _haystack;
|
_this select 0: <string> string to be found
|
||||||
_haystackLen = count _haystackArr;
|
_this select 1: <string> string to search in
|
||||||
_needleLen = count (toArray _needle);
|
|
||||||
|
Returns:
|
||||||
|
Boolean (true when string is found)
|
||||||
|
|
||||||
|
How to use:
|
||||||
|
_found = ["needle", "Needle in Haystack"] call KK_fnc_inString;
|
||||||
|
*/
|
||||||
|
|
||||||
|
private ["_needle","_haystack","_needleLen","_hay","_found"];
|
||||||
|
_needle = [_this, 0, "", [""]] call BIS_fnc_param;
|
||||||
|
_haystack = toArray ([_this, 1, "", [""]] call BIS_fnc_param);
|
||||||
|
_needleLen = count toArray _needle;
|
||||||
|
_hay = +_haystack;
|
||||||
|
_hay resize _needleLen;
|
||||||
_found = false;
|
_found = false;
|
||||||
if (_needleLen <= _haystackLen) then {
|
for "_i" from _needleLen to count _haystack do {
|
||||||
_hayArr = [];
|
if (toString _hay == _needle) exitWith {_found = true};
|
||||||
for "_i" from 0 to (_needleLen - 1) do {
|
_hay set [_needleLen, _haystack select _i];
|
||||||
_hayArr set [count _hayArr, _haystackArr select _i];
|
_hay set [0, "x"];
|
||||||
};
|
_hay = _hay - ["x"]
|
||||||
for "_i" from _needleLen to _haystackLen do {
|
|
||||||
if (toString _hayArr != _needle) then {
|
|
||||||
_hayArr set [_needleLen, _haystackArr select _i];
|
|
||||||
_hayArr set [0, "x"];
|
|
||||||
_hayArr = _hayArr - ["x"];
|
|
||||||
} else {
|
|
||||||
_found = true;
|
|
||||||
breakTo "main";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
_found
|
_found
|
||||||
Reference in New Issue
Block a user