¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

Re: String Parsing


 

Here: //Based on the sample data you've given I'm making the assumption that you'll get all the names you're after in a single query. This code will parse up to 10 names and those names would be overwritten with the next query.

#DEFINE_CONSTANT maxnames 10
#DEFINE_CONSTANT maxlength 40

Digital_Input Get_Names;
Buffer_Input RxData$[1000];
String_Output Actor$[maxnames][maxlength]; //Define an output array of 10 outputs, each up to 40 bytes in length

Integer i; //Define a global integer as the index

Push Get_Names
{
i = 1; //reset index to 1 when new request for name is sent.
}


Change RxData$
{
Integer semaphore; //Define a semaphore to prevent re-entrancy
String sTemp[100], sDump[50];

While(semaphore = 0)
{
Semaphore = 1;

sTemp = Gather("/>", RxData$); //this will remove each line from the buffer to be parsed individually

IF(FIND("person job=\x22Actor\x22 name=\x22",sTemp))
{

IF(i >= 1 && < maxnames){i = i + 1}; //increment index value if between 2 and 9

//parse as usual:

sDump = remove("person job=&#92;x22Actor&#92;x22 name=&#92;x22", sTemp);

Actor1[i]=left(sTemp, find("/>", sTemp)-3); //assign the parsed string to the output specified by the index [i]

Semaphore = 0;

}
}
}

You'll have to pardon any syntax errors as my iPad email app is not the best S+ text editor environment.

Hope that makes sense for you. This could also be done using a for loop but I thought you might understand this method more easily. You could also parse the name with a single mid statement and have no need to define sDump and save some memory but thats really irrelevant.

Ex. Actor$[i] = mid(sTemp, find("name=",sTemp) + 7,Len(sTemp) - ((find("/>", sTemp)-3) - (find("name=",sTemp))); //I'm almost sure to have missed a parenthesis but you get the idea.

-Neil Dorin
On Sep 16, 2012, at 10:16 PM, "chrmac68" <chrmac68@...> wrote:

Can you possibly give me an example of how to do this.
I have tried so many ways all without success.

Thanks

--- In Crestron@..., Neil Dorin <neildorin@...> wrote:

You're overwriting Actor1$ each time you parse a name. You need an integer variable to track how many names you've already parsed and use that as the index of the string output array you want to assign it to.

-Neil Dorin

Sent from my iPhone

On 2012-09-16, at 6:09 PM, "Chris" <chrmac68@...> wrote:

Sorry posted this in wrong place...

maybe im missing something here.
in s+
<person job="Actor" name="Brandon Lee" />
<person job="Actor" name="Rochelle Davis" />
<person job="Actor" name="Jon Thompson" />

im doing this:

IF(FIND("person job=&#92;x22Actor&#92;x22 name=&#92;x22",sTemp))
{

sDump = remove("person job=&#92;x22Actor&#92;x22 name=&#92;x22", sTemp);

Actor1$=left(sTemp, find("/>", sTemp)-3);

}

My output is always Jon Thompson. How can i get it to pull out 1 at a time and
assign to
Actor1$
Actor2$
etc.

Thanks




[Non-text portions of this message have been removed]

Join [email protected] to automatically receive all group messages.