Replacing strings
#1

Hello, its me again..

I use this lib: https://github.com/oscar-broman/strl...ter/strlib.inc
(from ******)

and made this function:

Код:
stock encryptDecrypt(data[])
{
	new search[] = {"a", "b", "c"};
	new replace[] = {"d", "e", "f"};
	strreplace(data, search, replace, true, 0, -1, strlen(data));
	return data;
}
Basically, this function should replace all chars from the search array to the chars from replace array.

Код:
encryptDecrypt("abc")
But the output still is abc.

Whats wrong?
Reply
#2

Use str_replace() instead of strreplace()
Reply
#3

I already did this, same result mate.
Reply
#4

You're returning data..
PHP код:
stock encryptDecrypt(data[])
{
    new 
search[] = {"a""b""c"};
    new 
replace[] = {"d""e""f"};
    new 
result[sizeof(data)] = strreplace(datasearchreplacetrue0, -1strlen(data));
    return 
result;

Reply
#5

Lets see, where to begin
For starters you are (at least to my experience) declaring strings wrong, characters need to be enclosed by ('), not ("), or why wouldn't you just do "abc"? because this function is called string replace for a reason, it doesn't look for "a" or "b" or "c", changing them to "d", "e" and "f" in the order from replace, it looks for whatever search is, replace it with replace string.
secondly why do you return data? strings are passed by reference into a function, so if you use encryptDecrypt(string) somewhere, the string automatically changes with whatever happens to it in the function (it can cause some serious bugs as you might lose the original string)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)