Replace() and .Replace() won't function for me?

Started by Yellownakji, April 27, 2019, 03:57:31

Previous topic - Next topic

Yellownakji

I tried:


if n.contains("<") then replace(n,"<","")
if n.contains("?") then n.replace("?","")


Looking for illegal characters, basically...

Nothing happens.  What am i doing wrong?.....

therevills

If I recall correctly replace is a function call. so you need to assign it to a variable:

if n.contains("<") then n = replace(n,"<","")

Yellownakji

Quote from: therevills on April 27, 2019, 04:12:36
If I recall correctly replace is a function call. so you need to assign it to a variable:

if n.contains("<") then n = replace(n,"<","")

Thank you!

Henri

Every string has a Replace-method, so you can also write:

Code (blitzmax) Select

if n.contains("<") then n = n.replace("<","")


Only gain using the method version is that Replace-function is part of BRL.Retro module, and by not using it, you can reduce few bytes from your executable size.

-Henri
- Got 01100011 problems, but the bit ain't 00000001