Reversing a string?

How would I go about reversing a string? I can't think of an
effective way to do this.

Here's a quick and dirty one:
var f = "Hello World!";
trace(f.split("").reverse().join(""));
Dave -
Adobe Community Expert
www.blurredistinction.com
www.macromedia.com/support/forums/team_macromedia/

Similar Messages

  • ResultEvent object is reversing my string values. Why?

    Hello
    Here is another wacky problem I am facing, maybe someone here can clarify or shed some light on this.
    I have a web service and HTTPService object that invokes it. I get data back just fine. I noticed though, that some of the data is reversed.
    Here is the raw data output, from my WSDL. This is what the Web Service really returns:
    Now, here is what I get from my ResultObject:
    Why is this value reversed? Is FLEX actually trying to help me by reversing this?
    I now must perform a reverse string hack, which I can handle. But why would the ResultEvent be reversing string values? Just because it has a lot of period characters in it? Riddle me this Batman???

    I am unsure what you mean by "server".
    I kind of need my server in the equation because it supplies my data via Web Service, lol. It is required.
    I am not using XML either.
    Test case? Do you mean to try the ArrayCollection test scenario jbf00 suggested? Or some other test case?
    I havent tried it because:
    1.) I dont have time, I have to many other bugs to try to fix.
    2.) I am pretty sure the problem will persist in an XML object or ArrayCollection object.
    Unless those objects perform string reversals magically.

  • Inline reverse of String or array

    Hi I have problem as follows
    I want to reverse String or Array by inline reverese
    means rebversing the string using same object no new one get created
    plz help me to do this

    public class a {
         public static void main(String arg[]) {
    System.out.println(doit(new
    ew StringBuffer(arg[0])));
         public static StringBuffer doit(StringBuffer sb) {
         int i=0,j=sb.length()-1;
              while(i<j) {
                   char tmp=sb.charAt(i);
                   sb.setCharAt(i,sb.charAt(j));
                   sb.setCharAt(j,tmp);
                   i++;
                   j--;
              return sb;
    }Assignment 1, question 1, done! Now what's question 2? And perhaps you can
    give us a heads-up on the midterm application.

  • String parsing (reversing)

    Hello friedns,
    I have string of the form :
    String s1 = "alex box (hello (how (are))) (sachin how are you) d  you"I want to reverse this string as follows :
    String reversed = "you d (sachin how are you) (hello (how (are))) box alex"Note : In the above translation if there is something inside parenthesis then,
    I want to use it as a single word and I will not reverse the content inside it.
    Would somebody can tell me how can I make such type of translation ?
    Thank you.
    regards,
    sachin

    sachin.annadate wrote:
    Hello friedns,
    I have string of the form :
    String s1 = "alex box (hello (how (are))) (sachin how are you) d  you"I want to reverse this string as follows :
    String reversed = "you d (sachin how are you) (hello (how (are))) box alex"Note : In the above translation if there is something inside parenthesis then,
    I want to use it as a single word and I will not reverse the content inside it.
    Would somebody can tell me how can I make such type of translation ?
    Thank you.
    regards,
    sachinThis looks a lot like your previous post:
    [http://forum.java.sun.com/thread.jspa?threadID=5301673]
    I suggested looking at ANTLR. I will do so again: create a grammar of your language and then let ANTLR do the "dirty" work by generating a lexer and parser for you.

  • Creating a string, reversing it, and than comparing with another one

    // get input
    InputStreamReader is = new InputStreamReader (System.in);
    BufferedReader in = new BufferedReader (is);
    String str = in.readLine ();
    // get length of input
    int len = str.length ();
    // reverse the input
    //String rts = "";// = new String[len];
    //for (int i=0; i<len; i++) rts.concat (str.charAt (len - i));
    StringBuffer rts = new StringBuffer(str).reverse ();
    // display the reversed string
    System.out.println(rts + "\n");
    // end if input was "tiuq"
    if (rts == "quit") break;I am accustomed to C language, now trying to learn Java. The string operations are still too much for me.
    In the code above, I managed to reverse my string using a "StringBuffer" object (still i don't know what it is), but couldn't compare it with "quit" constant. Compiler give "imcompareble types" error message.
    *1) How can I compare a StringBuffer with a constant?*
    On the other hand, why didn't my for loop didn't work (the commented-out one)? This time compiler says "java.lang.String cannot be applied to (char)".
    *2) How can I make this method work?*
    I also tried something like this:String[] rts = new String[len];
    for (int i=0; i<len; i++) rts[i] = str[len - i];But in this way, I couldn't find a way to compare str with the constant "quit".
    *3) How can I compare a String with a constant?*
    Can someone answer help me out on these 3 questions?

    hkBattousai wrote:
    @Skydev2u
    Why did you use nested fors? It can already be done with only one for loop. I didn't understand your logic.
    Anyway, my code works, and it is as follows:// get input
    InputStreamReader is = new InputStreamReader (System.in);
    BufferedReader in = new BufferedReader (is);
    String str = in.readLine ();
    // get length of input
    int len = str.length ();
    // reverse the input
    StringBuffer rts = new StringBuffer(str).reverse ();
    // display the reversed string
    System.out.println(rts + "\n");
    // end if input was "tiuq"
    if (rts.toString().equals("quit")) break;What I want to learn is, isn't a way to realize this without using that StringBuffer thing? Can you propose a mathod that merely uses the String class?I used the nested loops because I thought it would make the code clearer but at the same time i didn't really understand what you were doing since I don't know much about StringBuffer class. But from your reply I see that it was not needed.
    (The above stated is my best understanding of the concept. Use it as a guideline to answering your question)

  • Reversing string without using StringBuffer

    Hello,
    I am needing some help in reversing a string like the one below:
    "go to Way" to the string "Way to go"
    I know by using a StringBuffer you can change it to "og ot yaW"
    but that is not what I am trying to do. I am just trying to change the order of the words within the string. Any help would be greatly appreciated.
    thanks

    Hi,
    I suggest that you use the BreakIterator of java.text which is better suited for natural language. I have modified the example from the javadocs to produce a method that does the job for a specified locale. You can always use Locale.getDefault() to obtain the default locale.
    String reverseWords(String sentence, Locale locale) {
        StringBuffer s = new StringBuffer();
        BreakIterator i = BreakIterator.getWordInstance(locale);
        i.setText(sentence);
        int end = i.last();
        for (int start = i.previous();
             start != BreakIterator.DONE;
             end = start, start = i.previous()) {
            s.append(sentence.substring(start, end));
        return s.toString();
    }The code:
    System.out.println(reverseWords("Way to go", Locale.getDefault()));yields the output:
    go to WayOf course, capitalization and punctuation is a much bigger problem to reverse in a meaningful way.
    Regards,
    S&oslash;ren Bak

  • Can anyone help with reverse String?

    Hi, Can anyone help me in reversing the string?
    here is Code but it doesn't work well. it just give me the starting word of string.
    public class stringrev {
              //construct String
    private String str;          
    public String reverse (String str) {
    int len =str.length();
              if (len <=1)
              return str;
         String s1= str.substring(0,len-1);     
         return reverse(s1);
    public static void main (String [] args)     {
              stringrev str = new stringrev ();
              String reverse = str.reverse ("jinux 2000");
              System.out.println("Reversed String " +" " + reversed );
    }          

    haven't tested it, but the idea should be ok:
    public String reverseString(String s)
         String t = "";
         for(int i=s.length()-1;i>=0;i--)
              t += s.substring(i,i+1);
         return t;
    }tobias

  • Parsing a string to a boolean array

    I got to pase a string to a boolean array, this code works for me, but I don't like it. Here Is
    public static boolean[] NumeroToBoolArray( int Numero )
    //Here I got the number in Binary Format, then reverse it
    String temp = new StringBuffer(Integer.toBinaryString(Numero)).reverse().toString();
    //Now I create a boolean array of temp.length
    boolean[] data_bool = new boolean[temp.length()];
    for (int pp = 0; pp < data_bool.length ; pp++)
    //And now assign the value to data_bool
    data_bool[pp] = String.valueOf(Character.digit(temp.charAt(pp), 10)).equalsIgnoreCase("1");
    return data_bool;
    Any idea or replacement for this function?
    Thanks

    data_bool[pp] = String.valueOf(Character.digit(temp.charAt(pp),10)).equalsIgnoreCase("1");becomes
    data_bool[pp] = temp.charAt(pp) == '1';

  • How can I write this string to a file as the ASCII representation in Hex format?

    I need to convert a number ( say 16000 ) to Hex string ( say 803E = 16,000) and send it using Visa Serial with the string control in Hex Mode. I have no problem with the conversion (see attached). My full command in the hex display must read AA00 2380 3E...
    I can easily get the string together when in Normal mode to read AA0023803E... but how can I get this to hex mode without converting? (i.e. 4141 3030 3233 3830 3345 3030 3030 3031 )
    Attachments:
    volt to HEX.vi ‏32 KB

    Sorry, The little endian option was probably introduced in 8.0 (?).
    In this special case it's simple, just reverse the string before concatenating with the rest.
    It should be in the string palette, probably under "additional string functions".
    (note that this only works in this special case flattening a single number as we do here. If the stat structure is more complex (array, cluster, etc.) you would need to do a bit more work.
    Actually, you might just use typecast as follows. Same difference.
    I only used the flatten operation because of the little endian option in my version.
    Message Edited by altenbach on 11-16-2007 11:53 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    littleendian71.png ‏4 KB
    littleEndiancast71.png ‏4 KB

  • Reading File Reverse

    Hi,
    actully the problem is this i have a very big log file and i want to read last few lines but the requirment is this i want to read data line by line. in other words how can we open a file and read data line by line From EOF to BOF...... thanx in advance

    import java.io.*;
    import java.util.*;
    public class Example {
         public Example() throws IOException {
              String lines[] = readReverse("example.txt");
              // print the lines
              for (int j = 0;j < lines.length;j++) {
                   System.out.println(lines[j]);
         protected String[] readReverse(String file) throws IOException {
              BufferedReader b = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
              ArrayList al = new ArrayList(0);
              String s = "";
              while ((s = b.readLine()) != null) {
                   al.add(s);
              // reverse it
              String lines[] = new String[al.size()];
              for (int j = 0;j < lines.length;j++) {
                   lines[j] = (String)al.get(al.size()-(j+1));
              return lines;
         public static void main(String[] args) {
              try {
                   new Example();
              catch (IOException e) {
                   e.printStackTrace();
    }

  • How to get separators from a string

    I need to find the thousand separator, hundred separator and decimal separator from a string. I need to check which separator is available in a string ie., thousand or hundred separator. There may be a case where there is no separators.
    Please suggest me. I would be greatful if you provide me a code snippet.
    Thanks in advance...

    Hi Ananth,
    Try following:
    //For decimal fraction
    if (Count(Split(StrReverse(ToText ({OINV.DocTotal})), '.') ) > 1) then "With Decimal" else "Without Decimal"
    //For Units
    //Convert numbers to string valule
    //Reverse the string so that you cold parse them accordingly in units, hundreds, thousands etc
    //and finally split and parse each comma
    if
        Length
            Split
                    (Split(StrReverse(ToText ({OINV.DocTotal})), '.')[2]) , ','
                )[1]
        ) <= 2
    ) Then "Hundreds"
    Else "Thousands"
    You can continue on length of each subscript in array for hundreds, thousands, millions...
    Cheers,
    Kashif Ali

  • Displaying a mix of L to R and R to L readable strings in a single text box

    Folks,
    Is it possible to get accurate display of fields when  English string values and hebrew characters are dragged into a single text box for viewing.
    Currently while doing this the display gets erratic as some of the english strings gets displayed in the middle of a hebrew word.
    the whole text box data needs to be read as R to L , with the exceptions of a few English string DB values.
    Is this achievable ?  Thanks for your help.
    -Jayakrishnan

    Thanks for your reply Jamie.
    I am not sure whether I made my requirement really clear.
    I have these formula which display words in multiple languages, say english , hebrew , korean etc. The data value for this formula will be supplied by the framework externally at run time depending on which language has been selected.
    Now for this scenario I got to display 50 + objects in a concatenated fashion containing the combination of above said formula ( Labels ) and their DB values.
    For hebrew language the text growth should be R to L even if it would containg DB fields which may be integers or strings.
    The logic you have mentioned in the txt file, I have not understood why we need to reverse the string as I am assuming the characters would be laid out correctly.
    The missing part is when the string grows to the next line the printing should start from the Right and not from the Left.
    Hope this would be a little more clear.  Appreciate your time.
    -Jayakrishnan

  • Need help with a reverse number method

    hey all..
    i have this program which should return the integer reversed ..
    i have done this program using methods.. but the problem is if the
    number endes with 0 when it reversed the output doesn't contain the number 0
    for example:
    input
    123450
    output
    54321
    where before the 5 there should be 0
        This program that reads an integer and then calls a method
          that receives an integer and returns the integer with its digits reversed.
          Main prints the resulting integer.
       import java.util.Scanner; // program uses class Scanner
        class Sh9q4
           // main method begins execution of Java application
           public static void main( String args[] )
          // create Scanner to obtain input from command window
             Scanner input = new Scanner( System.in );
             int number; // The number entered by the user
             System.out.println("Enter an integer"); // prompt for input
             number = input.nextInt(); // read the the integer
             reverse (number); // print the method reverse
          } // end method main
           public static void reverse ( int num )
             int lastDigit; // the last digit returned when reversed
             int reverse = 0;
             do
                lastDigit = num % 10;
                reverse = (reverse * 10) + lastDigit;
                num = num / 10;
             while (num > 0);
             System.out.println("The integer with its digits reversed " + reverse); // print the integer reversed
          }// end method reverse
       } // end class Sh9q4thanks for your help :)

    If you need the leading zero to display, then you will have to do as Keith recommended and convert the input number to a String, then reverse that String and print it as a String.
    A number is a number is a numerical value, and there is no difference between the value of 054321 and 54321 except when written as a literal, when the first is an octal, and the second a decimal, value.
    If you are still confused, plug in these few lines of code and run them:String str = "012345";
    int x = Integer.parseInt (str);
    System.out.println(str);
    System.out.println(x);db

  • REVERSE function

    Hey There !!
    Here is a query that I execute and get the following output:
    select reverse('RAJU') from dual;
    UJAR
    I have defined no Function by this name. This means, REVERSE is an Oracle function to reverse the string. However, I guess, this is not a SQL function. Can anyone tell me what is the source for this function.
    I sincerely appreciate your help.
    Thanks,

    Hallo,
    i found following by asktom:
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:2424495760219
    "Note REVERSE is an undocumented function and, as such, should be used
    carefully. I do not recommend using REVERSE in “real” code, as its undocumented
    nature implies that it is not supported."
    Regards
    Dmytro

  • Return chars to right of first dot from right in string

    Anyone know how to return file extensions in BO? Ex. Return "doc" where file name = "document.doc" or where file name = "document.asdf.lkjh.123.doc".  I have some files names that contain 8 or more dots, so need to find first dot from right and return all chars to the right of it.

    Jeff,
    Without predictability to the data, the ability to identify the placement of the final period (.) in a string and then display that final portion is impossible with the given functions provided in WebI.  Two factors are against us here:  1) you cannot perform a loop (a do, while, end or similiar construct), or 2) there is no "reverse" function.  a Reverse function reads a column (string) and places the last character first, the second-to-last character second, etc, etc.   If there were a reverse function you could reverse the string and then use the POS function to find the first period, then use the left function on what is returned and then reverse again to put it in the original sequence again.  I'm working with MS SQL Server and there is a reverse function there, but I'm not sure what your database vendor is.  If you have a reverse function in your DB engine, perhaps you can perform your string manipulation via the universe, dressing it up at the DB layer and using WebI to perform the reporting phase.
    Thanks,
    John

Maybe you are looking for

  • Report development for tds deducted on expense GL accounts

    Dear Friends, I have to develop one report for the with holding tax deducted on the expense GL accounts. In the select lay out I will enter the  expense GL range and company code and posting date range. when I execute it has to show as               

  • Umlaut chracters in Teradata tables.

    This is regarding umlaut characters in Teradata tables. Few column values contain umlaut characters like PCE D�COUP�E 8591. I got to find these values containing umlaut characters in a column. The above string has to be converted to PCE DCOUPE 8591 o

  • Post-it notes

    I have Adobe Reader 8.1.3   A report was sent ot me with post it notes on it. I can see them but cannot get then to print.  Please help

  • Inbox is missing on my mailbox list

    The "inbox" title and a couple of my mailboxes can only be seen if I drag the mailbox listing downward. I can't access them though because when I let go they pop back up out of site. Wasn't always like this and I don't know what I've done. Help?

  • STBO sets on any read?

    Using a TNT4882 in an instrument that I am designing, I monitor STBO (ISRO bit 6) to reset rsv in order to de-select the SRQ line. I set rsv via the AUXMR reqt command. I expected STBO to trigger on a serial poll command and/or *STB?, but discovered