Change font size
It is currently Sat Dec 15, 2018 2:23 pm

Forum rules


{L_IMAGE}



Post a new topicPost a reply Page 1 of 1   [ 3 posts ]
Author Message
 Post subject: Search and Replace function
PostPosted: Mon Jun 25, 2012 10:12 pm 
Furious Typer

Joined: Fri May 11, 2012 9:37 pm
Posts: 51
Location: Canada
Is there yet a search and replace function one can use on a string in an opensim script that would work llike Perl's $string =~ s/apples/oranges/; ?

- Nova


Top
 Profile  
 
 Post subject: Re: Search and Replace function
PostPosted: Tue Jun 26, 2012 8:18 am 
Furious Typer
User avatar

Joined: Mon Aug 10, 2009 11:53 pm
Posts: 258
I think this might be what you are looking for...

EDIT: This is a handy dandy function for search/replace I've used forever for substring find/replace straight from the old SL days right from the LSL site:
{L_CODE}:
string str_replace(string src, string from, string to)
{//replaces all occurrences of 'from' with 'to' in 'src'.
    integer len = (~-(llStringLength(from)));
    if(~len)
    {
        string  buffer = src;
        integer b_pos = -1;
        integer to_len = (~-(llStringLength(to)));
        @loop;//instead of a while loop, saves 5 bytes (and runs faster).
        integer to_pos = ~llSubStringIndex(buffer, from);
        if(to_pos)
        {
//            b_pos -= to_pos;
//            src = llInsertString(llDeleteSubString(src, b_pos, b_pos + len), b_pos, to);
//            b_pos += to_len;
//            buffer = llGetSubString(src, (-~(b_pos)), 0x8000);
            buffer = llGetSubString(src = llInsertString(llDeleteSubString(src, b_pos -= to_pos, b_pos + len), b_pos, to), (-~(b_pos += to_len)), 0x8000);
            jump loop;
        }
    }
    return src;
}


llListFindList
and
llListReplaceList

Take care,
- Hap

_________________
Sorry, I was just thinking upon the immortal words of Socrates who said ... "I drank what?? ... "
- Real Genius


Top
 Profile  
 
 Post subject: Re: Search and Replace function
PostPosted: Tue Jun 26, 2012 10:10 am 
Furious Typer

Joined: Fri May 11, 2012 9:37 pm
Posts: 51
Location: Canada
Thank you Haplo. Just the thing!

- Nova

[ Edit:

Eventually settled on the following:
(Found at: http://opensim-users.2152040.n2.nabble.com/strReplace-not-functioning-in-OpenSim-td6626793.html)

{L_CODE}:
//function strReplace: Will search & replace text in string
string strReplace(string str, string search, string replace) {
     return llDumpList2String(llParseStringKeepNulls(str,[search],[]), replace);
}


Example call to function which removes all colons (:) from string url replacing them with "":

{L_CODE}:
url=strReplace(url,":",""); 


]


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 3 posts ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
610nm Style by Daniel St. Jules of Gamexe.net