Does ebasic have string functions similar to C string functions?
I need to do the following:
stringa = "this is a string containing %stuff% and more %things% and so on"
I want to create a second string that substitutes variable length text in place of the %...%.
examples of the inserts could be:
stuff = "rocks, boxes, trees"
things = "this is a bunch of things"
Is there an easy way to do this?
stringa = USING("&&&&&","this is a string containing ", stuff, " and more ", things, " and so on")
This is one way to do it where stuff and things are string variables containing anything.
Or even:
stringa = USING("this is a string containing & and more &", stuff, things)
Which is a little more readable.
Paul.
I almost understand - but ---
string a is passed to me from another function.
I do not know where or what will be between the %% (keyword)
I have a list of keywords and depending on what is between the %% will
determine the substitution.
So - how would I do this with USING?
The following code should do what you are looking for:
' PCT = String to find
DEF PCT:STRING
' SSTR = Starting String
DEF SSTR:STRING
' NSTR = New String
DEF NSTR:STRING
' RSTR = Replacement for PCT
DEF RSTR:STRING
DEF I,L:INT
OPENCONSOLE
PCT = "%TEST%"
SSTR = "Replace %TEST% with something else"
RSTR = "testing"
L = LEN(PCT)
I = INSTR(SSTR,PCT)
IF I > 0 THEN NSTR = MID$(SSTR,1,I - 1) + RSTR + MID$(SSTR, I + L)
PRINT NSTR
DO
UNTIL INKEY$ <> ""
CLOSECONSOLE
END
Hope this helps,
Bill
I think the ExpandEnvironmentStrings function will be faster
$include "windowssdk.inc"
SetEnvironmentVariable("stuff", "stuff_value")
SetEnvironmentVariable("things", "things_value")
string out
ExpandEnvironmentStrings("Hello %username%, this is a string containing %stuff% and more %things% and so on", out, 256)
print out
_system("pause")
I do not seem to have windowssdk.inc.
Where do I find it?
Look at the footer at the bottom on all of Sapero's posts.
Larry
Thx - I thought I had installed it but had not - got it now.
Thanks to you guys I now have it working.
Moving on to my next road block. :)