azro Maktoum Posted September 5, 2011 Share Posted September 5, 2011 Hi EveryoneI need just Function INVERSION number Exampl ( hi everyone 532 > hi everyone 235) How can i do it? thanks Link to comment Share on other sites More sharing options...
Void Singer Posted September 5, 2011 Share Posted September 5, 2011 uStringReverse (you'll need to feed it just the part you want to reverse) Link to comment Share on other sites More sharing options...
azro Maktoum Posted September 5, 2011 Author Share Posted September 5, 2011 Thanks but how can i specifay Reverse Only numbers not all String i Can't Do it plz help Link to comment Share on other sites More sharing options...
Rolig Loon Posted September 5, 2011 Share Posted September 5, 2011 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 More sharing options...
PeterCanessa Oh Posted September 5, 2011 Share Posted September 5, 2011 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 More sharing options...
Rolig Loon Posted September 6, 2011 Share Posted September 6, 2011 More compact and faster than mine, Pete. AND it will handle more than one number per string. I like it. :smileyhappy: Link to comment Share on other sites More sharing options...
azro Maktoum Posted September 6, 2011 Author Share Posted September 6, 2011 thanks Peter, rolig Its Work :matte-motes-inlove: Link to comment Share on other sites More sharing options...
Recommended Posts
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