cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
jmulcahy
Level 2

Finding an unknown string between two known strings

Hi everyone,

I tried searching for this, but I couldn't find an answer. During one of our installs, we are allowing the user to update which database they are pointing too, this information is stored in an XML file. I have code to replace that value, but I wanted to read that value before hand so we can display where it's currently pointed. I'm having trouble finding out how exactly to do that. I know the string that comes before the machine name, and the one after, but I will never be able to tell what the actual value is, nor the length of it. Is there an easy function to do this?

I'm looking for a function that would take an input like this:

stringStart = '"'
findString(startString, endString);

is this possible?
Labels (1)
0 Kudos

(1) Reply
RobertDickau
Flexera Alumni

Searching these forums for "installscript xml" will turn up some sample code for reading XML documents, and I think there's some regular expression code sprinkled here and there.

Otherwise, an old-old-school approach might be (usual disclaimers about lack of error checking, worked once on one machine, etc.):

function OnBegin( )
STRING searchme, before, after, foundit;
NUMBER beforepos, afterpos;
begin

// beginning and end of your string
before = '';

// in practice, this is the string you read from the file, of course
searchme = before + "servo" + after;

// find where the prefix ends and the postfix begins
beforepos = StrFind(searchme, before) + StrLengthChars(before);
afterpos = StrFind(searchme, after);

// drag out the characters in that range
StrSub(foundit, searchme, beforepos, afterpos - beforepos);

// here's hoping:
MessageBox("Found it: " + foundit, INFORMATION);

end;
0 Kudos