Le Friday 24 October 2008 10:27:47 Jean-Francois Mauguit, vous avez écrit :
> Hello,
Hi again !
> I'm trying to make a string replace in a liq file.
>
> My syntax is
> string.replace(pattern="_", " ", description)
>
> So I try to replace _ by space in the description variable but it
> doesn't work.
>
> Any idea ?
Yep :)
string.replace may handle powerfull matching via regular expressions, like
[\w]{4} which will replace all sequence of 4 alphanumerical characters.
Hence, the replaced string may not be static. Instead, you should pass a
function to which the matched stirng is passed and that returns the replaced
string.
For instance, a correct implemtation of your needs is:
def f(x) =
" "
end
bla = string.replace(pattern="_",f,bla)
Or, alternatively:
bla = string.replace(pattern="_",fun (_) -> " ",bla)
For means of simplicity, you may also define a new operator:
def string.replace.static(~pattern,r,s) =
string.replace(pattern=pattern,fun (_) -> r,s)
end
More generaly, you may put all your custom operators in a seperate custom.liq
file, and include them in your scripts, using
%include custom.liq
Of course, new operators that you find very usefull may be considered for
inclusion into the standard set of operators, which may include
string.replace.static for instance.. :)
Romain
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Savonet-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/savonet-users