October 29, 2025, 07:11:51 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


String functions

Started by Rock Ridge Farm (Larry), December 04, 2008, 08:05:52 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Rock Ridge Farm (Larry)

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?

Hootie

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.

Ionic Wind Support Team

Or even:

stringa = USING("this is a string containing & and more &", stuff,  things)

Which is a little more readable.

Paul.
Ionic Wind Support Team

Rock Ridge Farm (Larry)

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?

billhsln

December 04, 2008, 09:37:14 AM #4 Last Edit: December 04, 2008, 09:38:59 AM by billhsln
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
When all else fails, get a bigger hammer.

sapero

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")

Rock Ridge Farm (Larry)

I do not seem to have windowssdk.inc.
Where do I find it?

LarryMc

Look at the footer at the bottom on all of Sapero's posts.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Rock Ridge Farm (Larry)

Thx - I thought I had installed it but had not - got it now.

Rock Ridge Farm (Larry)

Thanks to you guys I now have it working.
Moving on to my next road block. :)