Jump to content

Need Help Function


azro Maktoum
 Share

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

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

Recommended Posts

If the number is in a longer string, you'll have to script some way to parse the string and recognize just numerals.  That's going to be a slow step, no matter how you do it.  Here's one possible solution........

 

integer FindNumber(string Str){     integer idxB;  // This variable will hold the position of the first numeral in Str     integer idxE;  // This one will hold the position of the last numeral in the substring that starts with idxB     integer i;     for (i=0;i<llStringLength(Str);++i) // Find the first numeral in the string     {          if (~llListFindList(["1","2","3","4","5","6","7","8","9","0"],[llGetSubString(Str,i,i)]))          {               idxB = i;  // This is the position of the left-most numeral               jump ahead;           }     }     @ahead; // OK, now we know where the number starts     for (i=idxB+1;i<llStringLength(Str);++i)  // Examine each character in Str to the right of position idxB     {          if (!~llListFindList(["1","2","3","4","5","6","7","8","9","0"],[llGetSubString(Str,i,i)]))  //If it's NOT a numeral....          {               idxE = i-1;   // Here's the position of the first non-numeral to the right of idxB               jump out;   //We don't need to look further....          }     }     @out;     return (integer)llList2String(Str,idxB,idxE);   // Here's the number that was buried in Str}

 

 

 If there's more than one number in the string, of course, this will only find the first one.

 

              

Link to comment
Share on other sites

string uStringReverse( string vStrSrc ){    integer vIntCnt = llStringLength( vStrSrc );    while (vIntCnt){        vStrSrc += llGetSubString( vStrSrc, (vIntCnt = ~-vIntCnt), vIntCnt );    }    return llGetSubString( vStrSrc, llStringLength( vStrSrc ) >> 1, 0xFFFFFFFF );}//                       Anti-License Text//     Contributed Freely to the Public Domain without limitation.//   2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ]//  Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ]string InverseNumbers(string Message){	// Split the message into a list of words, delimited with spaces	list Words = llParseString2List(Message, ["  ", " "], []);	integer Counter = llGetListLength(Words);	while(Counter--){		// Test each word		if((float) llList2String(Words, Counter) != 0.0){			// If a 'word' is actually a number then it'll be a non-zero float, so reverse it			// (if it IS zero then it doesn't need reversing!			Words = llListReplaceList(Words, [uStringReverse(llList2String(Words, Counter))], Counter, Counter);		}	}	// Stick all the words back together again, with spaces	return llDumpList2String(Words, " ");}

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4617 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...