Convert word

Posted by Khuran on Thu 16 Sep 2021 02:59 AM — 2 posts, 11,705 views.

#0
this is a continuation of this post

http://www.gammon.com.au/forum/bbshowpost.php?id=8747&page=2

your suggestion to use this


conversions = {
[GetPluginVariable ("", "char1")] = GetPluginVariable ("", "char1").."-[1]",
[GetPluginVariable ("", "char2")] = GetPluginVariable ("", "char2").."-[2]"
}



worked!

the output comes out as this with char1=Yinn


Yinn-[1] barely hits a centipede.  ---- line 1
A centipede misses Yinn-[1] with its bite.  ---- line 2


If I wanted the substitution to occur only on instances like line 2 (basically with a <space> in front of the variable, how do I go about it?

I tried this and it did not work.


[ " " .. GetPluginVariable("", "char1")] = " " .. GetPluginVariable("", "char1").. "-[1]"


Thank you

[EDIT] Fixed formatting
Amended on Thu 16 Sep 2021 04:33 AM by Nick Gammon
Australia Forum Administrator #1
From the page you reference:


 return (string.gsub (s, "%a+", conversions))


The match is on one or more letters and therefore a space will not be part of the match.

Perhaps change it to:


 return (string.gsub (s, " %a+", conversions))