How to grab specific words from reading line of text - Forum

Forum Navigation
You need to log in to create posts and topics.

How to grab specific words from reading line of text

I'm trying to make my program read a server config but grab the server name values only, from a line of text. I need some help on grabbing a specific text, my code so far is:

FileRead "[PubDir]serverconfig.xml" "6" "[servername]"

SetObjectCaption "Text30" "[servername]"

Then I would like to set the caption to whatever the server name value is so people can see right away what their server name is set to.

Any suggestions or help much appreciated, thank you!

 

 

 

 

 

Uploaded files:
  • You need to login to have access to uploads.

@jaydencone

a) I am not sure why you are reading Line number 6 ... in the image, it looks like the information you want is in Line number 5 (including the blank line)

In any case, since this may change in the future, read the entire file into the variable

FileRead "[PubDir]serverconfig.xml" "All" "[xmlData]"

b) Now parse on the (hopefully unique) string value of ServerName

StrParse "[xmlData]" "ServerName" "[serverNameLine]" "[junk]"

... you will now have an array called [serverNameLine]. The second element (i.e. [serverNameLine2]) will contain all the text after the string value of ServerName.

c) Within this second array element, you are interested in the text after value=" ...

StrParse "[serverNameLine2]" "value=[#34]" "[serverNameToEndOfFile]" "[junk]"

... note that [#34] is the code for the double quotes character.

d) you now want to separate the server name from the subsequent text (i.e. everything from "/> to the end of file ...

StrParse "[serverNameToEndOfFile2]" "![#34]/>" "[serverNameAndRestOfText]" "[junk]"

... note the ! character is just so VisualNEOWin does not look at the / as a division symbol

e) The first array element (i.e. [serverNameAndRestOfText1]) now contains the name of your server ...

SetObjectCaption "Text30" "[serverNameAndRestOfText1]"

Please note that this script is not tested/verified as I do not have access to your serverconfig.xml file ... so be forewarned about possible typos.

 

luishp, Vadim and jaydencone have reacted to this post.
luishpVadimjaydencone

Thanks a lot! This works exactly how I wanted it to