Jump to content

Parsing a string help please ?


rasterscan
 Share

You are about to reply to a thread that has been inactive for 896 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hi ! Struggling to winkle out the region name out from the following string:

string slurl = " hppt// map s.secondlif e.co m/secondlif e/Sandbox Mirus/111/39/1113

I am trying to use

 list parsedString = llParseString2List(slurl, [" "], [" "]); to winkle out just the region name from that string. I cant figure it oot. Help !

 

 

Link to comment
Share on other sites

If you just want the region name from a slurl, then you'll want to split up the slurl by "/" and then grab the list element at index 3. Also, if this is coming straight from a slurl, you won't actually have spaces in the string - instead you'll want to put the result through llUnescapeURL to convert the "%20" characters to spaces.

default
{
    state_entry()
    {
        string slurl = "https://maps.secondlife.com/secondlife/Sandbox%20Mirus/111/39/1113";
        list parsedString = llParseString2List(slurl, ["/"], [""]);
        string unescaped = llUnescapeURL(llList2String(parsedString,3));
        llSay(0,unescaped);
    }
}

 

  • Like 2
Link to comment
Share on other sites

I don't know if that SL URL is broken intentionally or it broke when you pasted it into the post, but there are multiple ways.

1) If your SL URL will always have the correct format "http://maps.secondlife.com/secondlife/<region_name>/.../.../..." then you can simply do for example this:

list lst = llParseString2List(slurl, ["/"], []);
string regionName = llList2String(lst, 3);

It will work even in your exact case where the URL looks broken little bit. It however assumes that there will be always the correct number slash delimiters before the region name.

2) If you want a solution that will also do a basic check of SL URL and will even handle a slightly broken input, then you can for example do this (WARNING: quick and dirty code, expect bugs :) )

        string slurl = "hppt// ma p s.s eco ndlif e.co m/sec ondlif e/Sandbox Mirus/111/39/1113";
        
        // clean str from spaces
        string slurlCleaned = slurl;
        integer pos;
        while((pos = llSubStringIndex(slurlCleaned, " ")) >= 0)
            slurlCleaned = llDeleteSubString(slurlCleaned, pos, pos);
        
        // parse cleaned url
        list lst = llParseString2List(slurlCleaned, ["/"], []);
        
        // check if it is a SL URL
        if (llList2String(lst, 1) == "maps.secondlife.com"
            && llList2String(lst, 2) == "secondlife")
        {
            // return the region name from original (uncleaned url) to preserve spaces in region name
            llSay(0, llList2String(llParseString2List(slurl, ["/"], []), 3));
            // OR return the region name from cleaned url (will not preserve spaces in region name)
            llSay(0, llList2String(llParseString2List(slurlCleaned, ["/"], []), 3));
        }

There are also other ways, but really depends on what your input might be.

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 896 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...