azro Maktoum Posted September 19, 2012 Share Posted September 19, 2012 hi i want to reverse string A to Z Example i want reverse this String : Hello 240 meResult : olleH 240 em Plz Ty Link to comment Share on other sites More sharing options...
Darkie Minotaur Posted September 19, 2012 Share Posted September 19, 2012 This sould do the trick: string gsSource = "abc";default{ touch_end(integer total_number) { string revstring = ""; integer i = llStringLength(gsSource); while (i > 0) { i--; revstring += llGetSubString(gsSource, i, i); } llOwnerSay("This is the string in reverse: " + revstring); } } Link to comment Share on other sites More sharing options...
azro Maktoum Posted September 19, 2012 Author Share Posted September 19, 2012 ty but this code reverse all String i said reverse just English String A to Z no numbers Ty Link to comment Share on other sites More sharing options...
Darkie Minotaur Posted September 19, 2012 Share Posted September 19, 2012 Ahh - ok - I interpreted that as a typo. It would be helful if you stated such non-obvious matters. I think, what you want isn't really possible in the strictest sense. Apart from the fact, that you would have to define "English String" (what if expressions like a vector shows up - it's not an English word - but it's no number either. You could, hoever , to get as close as possible, look at something like this function (or the parts of it you need) to find out wehere you'd have to stop the reversal, generate the non-reversed sub-string, then insert this non-reversed sub-string into the new string an move on happily to reverse the string 1 Link to comment Share on other sites More sharing options...
Helium Loon Posted September 19, 2012 Share Posted September 19, 2012 Something along these lines should work: integer IsInteger(string var) { // This is from the wiki integer j; for (j=0;j<llStringLength(var);++j) { if(!~llListFindList(["1","2","3","4","5","6","7","8","9","0"],[llGetSubString(var,j,j)])) return FALSE; } return TRUE;}string ReverseString(string var) { string retval = ""; integer i; for(i=llStringLength(var); i > 0; i--) { retval += llGetSubString(var,i,i); } return retval;}string ReverseWords(string in){ list outlist = []; list words = llParseString2List(in, [" "], []); integer i; for(i=0; i<llGetListLength(words); i++) { if(IsInteger(llList2String(words,i)==FALSE) { outlist += [ ReverseString(llList2String(words,i)) ]; } else { outlist += [ llList2String(words,i)) ]; } } return llDumpList2String(outlist," ");} Then, wherever you want to reverse the non-number words in the string, simply call ReverseWords(whatever) and it should do it. 1 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