Shuffle characters in String

Hy,I'll start with a program i'm dealing with.
I need to shuffle the characters in a String besides the first and last character in some text file for example.
Well i started like this
i put the word in some String
then i make char[] c = s.toCharArray();
then make a list.
List l = Arrays.asList(c);
Collections.shuffle(l);
Of course this doesn't work,i suppose because the list can't take char array,but in doc it is Object[]..My question is:if it is there anyway to shuffle the characters of a String with shuffle method in Collections?

i wroted the program like this:
import java.util.*;
public class TextModifier{
          public static void main(String[] args){
                    StringTokenizer str = new StringTokenizer("Filip je all the best.Love him."," .");
                    String s;
                    String output = "";
                    while(str.hasMoreTokens()){
                              s = str.nextToken();
                              if(s.length() > 3){
                                        char[] c = s.toCharArray();
                                        Character[] ch = new Character[c.length];
                                        for(int i = 0;i < c.length;i++)
                                                  ch[i] = new Character(c);
                                        List l = Arrays.asList(ch);
                                        Collections.shuffle(l);
                              for(Iterator ite = l.iterator();ite.hasNext();){
                                        output += (String)ite.next()+" ";
                    System.out.println(output);
I hope you'll figure out what i wroted ,when i paste it paste like this.:)
Well comiler puts me this:
C:\java>javac TextModifier.java
TextModifier.java:18: cannot find symbol
symbol : variable l
location: class TextModifier
for(Iterator ite = l.iterator();
^
ite.hasNext();){
1 error
Why?

Similar Messages

  • Characters in String : Unicode 16-bit to custom 32-bit

    I understand that internally in Java, characters in Strings are actually Unicode characters, with each character represented with 16 bits.
    So, character �L� in Unicode is 0x004C
    which is also 0000 0000 0100 1100
    Now, I wish to encode each of the 4 bits above into individual ASCII characters:
    = 0 0 4 C
    = 0x30 0x30 0x34 0x43
    = 00110000 00110000 00110100 01000011
    So, from the original 16-bit character in Java, I want a final 32-bit.
    Eventually, I�ll need to send the final result over the network, via OutputStream/writer and socket.
    Can someone help me on this ? Or give me some ideas... Thanks.

    trick: prepend the number with 1 and use substring... like int charWith1 = c + 0x10000. That'll make charWith1 to be of the format 0x1XXXX. Then call hexstring on that, you get a string like "1XXXX." Then you can drop the 1 with a call to substring.
    of course there are methods that use only bit operations and additions to do it, making it a bit faster.. like this:
    byte byte0 = (byte) ((c & 0x000F) + '0');
    byte byte1 = (byte) (((c & 0x00F0) >> 4) + '0');
    ...

  • Removing non-numeric characters from string

    Hi there,
    I need to have the ability to remove non-numeric characters from a string and I do not know how to do this.
    Does any one know a way?
    Example:
    Present String: (02)-2345-4607
    Required String: 0223454607
    Thanks in advance

    Dear NickM
    Try this this will work...........
    create or replace function char2num(mstring in varchar2) return integer
    is
    -- Function to remove Special characters and alphebets from phone no. string field
    -- Author - Valid Bharde.(India-Mumbai)
    -- Date :- 20 Sept 2006.
    -- This Function will return numeric representation.
    -- The Folowing program is gifted to NickM with respect to his post on oracle site regarding Removing non-numeric characters from string on the said date
    mstatus number :=0;
    mnum number:=0;
    mrefstring varchar2(50);
    begin
    mnum := length(mstring);
    for x in 1..mnum loop
    if (ASCII(substr(upper(mstring),x,1)) >= 48 and ASCII(substr(upper(mstring),x,1)) <= 57) then
    mrefstring := mrefstring || substr(mstring,x,1);
    end if;
    end loop;
    return mrefstring;
    end;
    copy the above program and use it at function for example
    SQL> select char2num('(022)-453452781') from dual;
    CHAR2NUM('(022)-453452781')
    22453452781
    Chao!!!

  • Number of repeated characters in string array

    Hi,
    I m trying to get number of repeated characters in string array. I couldnt figure out where am i doing mistake.
    thank you,
    For example: count({"alpha, beta,"}, 'a')
    a is repeated 3
    l is repeated 1 etc.
    public class Test
    public static int count(String[] stringArray, char c)
    public String [] str = new String [2];
    int count = 0;
    str[0]
    str[1]
    for(int i = 0; i<str.length(); i++)
    if (str.charAt(i)
    count++;
    return count;

    There is a difference between a String and a String [].
    A String [] is an array of String class objects:/*  Traverse_Array_Of_Strings_1.java */
    public class Traverse_Array_Of_Strings_1
      public static void main(String [] argv)
        /* here is an array of Strings */
        String [] s = { "hello", "how", "are", "you" };
        int i, j;
        System.out.println("s.length = "+ s.length );
        for (i= 0; i < s.length; i++)
          System.out.println("s= <"+ s[i] +">");
          for (j= 0; j < s.length(); j++)
    System.out.print(s[i].charAt(j) +", ");
    System.out.println("\n-----");
    }output:java> javac Traverse_Array_Of_Strings_1.java
    java> java Traverse_Array_Of_Strings_1
    s.length = 4
    s= <hello>
    h, e, l, l, o,
    s= <how>
    h, o, w,
    s= <are>
    a, r, e,
    s= <you>
    y, o, u,
    Edited by: vim_no1 on Jul 15, 2010 7:43 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Replace special characters in String

    Dear Guru ,
    Does SAP provide the standard function that can replace the special characters in String ?
    For example :
    I have one template string : " & & & & & output(s) have not been processed yet ! " and five parameters : "P1" , "P2" , "P3" , "P4" , "P5" .
    And i would like to apply all parameters into the string to replace the "&" character . Is it possibile ?
    My idea is sourcing from the Message String that in tcode : SE91 .
    Thanks .
    Best Regards,
    Carlos Zhang

    Hi Carlos,
    I think instead of a standard FM you can write a one line command to do this job.
    E.g. 
    constant: str1 type string value 'output(s) have not been processed yet ! '.
    data: var1 type c,
             var2 type c,
             var3 type c,
             var4 type c,
             str    type string.
    concatenate var1 var2 var3 var4 str1 into str separated by space.
    So str will have the final value.
    Thanks,
    Mainak

  • Convert integers to equivalent characters in string - NOT ASCII code character

    I have to output my data and associated string information to a string array and then to a spreadsheet file.
    I want to do this by converting integers (and other numbers) to an identical string of characters.
    I have tried Type Cast with a string constant as the type input but it DOES NOT WORK.  Instead, I get the ASCII character whose numerical designation matches the integer, e.g. integer "50" become capital "P".
    I want integer "50" to be string "50".
    Please advise and no, I do not want to make arrays of clusters.
    Solved!
    Go to Solution.

    I found my answer but only after searching for "Number" conversion rather than "Integer" conversions.
    In the Programming palette  - String Functions - String/Number Conversion - Number to Decimal String:
    "Converts number to a string of decimal digits at least width characters wide or wider if necessary. If number is floating-point, it is rounded to a 64-bit integer before conversion."

  • How to Avoid Special Characters in string

    Hai.
    I want only Alphabets & Digits to be entered in to my string.No any other special characters except spaces.How can I do this? 
    Solved!
    Go to Solution.

    MikeS81 wrote:
    see the attached example.
    I would allow a few more, e.g. 0 and 8 to allow editing of the entered string (backspace, cursor buttons, delete key, etc.).
    Message Edited by altenbach on 11-21-2008 12:49 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    check_char_LV80MOD.vi ‏14 KB
    FilterStringInput.gif ‏6 KB

  • How to replace special characters in string.

    Hello,
    I want to replace special characters such as , or ; with any other character or " ".I find out there is no such function is java for this.There is only replace() but it accepts only chars.If anybody know how to do this?.
    Thanks,

    Hello,
    I want to replace special characters such as , or ;
    with any other character or " ".I find out there is no
    such function is java for this.There is only replace()
    but it accepts only chars.If anybody know how to do
    this?.
    Thanks,Can't you just do the following?
    public class Test
         public static void main(String[] args)
         String testString = "Hi, there?";
         System.out.println(testString.replace(',',' '));
    }

  • Search set of Characters in String in mapping

    Hello All,
    I want to search for a set of characters in a string and I want to do this in mapping.
    Can anyone help me in resolving this?
    Example:-
    String = "SAP PI is an Integration Tool"
    Search = "an Integ"
    OR
    just search for "an Integ" in the String.
    The String length can always change and the position of "an Integ" can also change.
    Please help!
    Thanks for your help and time,
    Abhi
    Edited by: Abhi_1516 on Nov 19, 2009 7:08 PM

    Thanks Sunil, for your quick response.
    I tried using that, but it's returning the index of the first occurrance of the Sub String and not "-1" as you have described.
    I am trying to write an UDF and I am getting syntax error ... where I am doing wrong?
    +int ind = (param2 + 7);+
    String str1 = param1.substring(param2,ind);
    String flag;
    if ( (str1.equals("an Integ")) )
    +     flag = "a";+
    else
    +     flag = "b";+
    return (flag);
    param1 and param2 are input parameter in the UDF.
    THanks for your help,
    Abhi
    Edited by: Abhi_1516 on Nov 19, 2009 7:35 PM

  • How to write this logic  in EL expression ? (new line characters in string

    iam using JSTL EL expression in my JSP.
    iam printing a string in JSP as ${vobject.rmessage} where rmessage is a string .
    problem is i want to identify the newline characters in the above rmessage string and print the line break <br> in html where ever the new lines character is present in the string.
    How should i write an EL expression for the above.
    Can anyone please guide me on writing EL expression for the above problem?

    Several ways. You can wrap the output with <pre> tags. You can apply CSS property white-space: pre; to the element. You can use String#replaceAll() in the Java code to replace each occurence of "\r\n" by "<br>".

  • Replacing non-ascii characters in String

    I have a site where the user enters data in a rich text
    editor (ktml4) that gets stored into a database (mysql). There are
    non ascii characters getting into the data, I'm assuming that they
    are copying and pasting from Word. Unfortunately in this situation,
    changing that process isn't an option.
    Currently, this is the only character that is causing me
    problems:
    http://www.zvon.org/other/charSearch/PHP/search.php?request=ffa0&searchType=3
    I would just like to replace the non-ascii characters with a
    space when I read them from the database. Something like:
    #Replace(result.column, '\xffa0', ' ')#
    However, I believe that code looks for the string "\xffa0",
    not the character \xffa0.
    Is there anyway to do this?

    quote:
    Originally posted by:
    BuckLemke
    quote:
    Originally posted by:
    Dan Bracuk
    rereplace might work.
    Can you give an example of how to pass a non-ascii character
    to REReplace?
    Regular expressions are not my strength, but the approach I
    was considering was, "if it's not an ascii character, make it a
    space". Then you pass the entire string at once.

  • Removing characters from string after a certain point

    Im very new to java programming, so if this is a realy stupid question, please forgive me
    I want to remove all the characters in my string that are after a certain character, such as a backslash. eg: if i have string called "myString" and it contains this:
    109072\We Are The Champions\GEMINI
    205305\We Are The Champions\Queen
    4416\We Are The Champions\A Knight's Tale
    a00022723\We Are The Champions\GREEN DAYi would like to remove all the characters after the first slash (109072*\*We...) leaving the string as "109072"
    the main problem is that the number of characters before and after is not the always the same, and there is often letters in the string i want, so it cant be separated by removing all letters and leaving the numbers
    Is there any way that this can be done?
    Thanks in advance for all help.

    You must learn to use the Javadoc for the standard classes. You can download it or reference it on line. For example [http://java.sun.com/javase/6/docs/api/java/lang/String.html|http://java.sun.com/javase/6/docs/api/java/lang/String.html].

  • Special characters in String variable sent from php.

    Hello. Assuming that I send some String variable from php into flash:
    AS3:
    var MyImportedString:String;
    var variables_page_text:URLVariables = new URLVariables();
    var varSend_page_text:URLRequest = new URLRequest("MyPHP.php");
    varSend_page_text.method = URLRequestMethod.POST;
    varSend_page_text.data = variables_page_text;
    var varLoader_page_text:URLLoader = new URLLoader;
    varLoader_page_text.dataFormat = URLLoaderDataFormat.VARIABLES;
    varLoader_page_text.addEventListener(Event.COMPLETE, var_comp_page_text);
    varLoader_page_text.load(varSend_page_text);
    function var_comp_page_text(event:Event):void {
        MyImportedString =  event.target.data.MyVariable;
    php:
    <?php
    header('Content-Type: text/html; charset=utf-8');
    $MyString = "some tekst &";
    print "MyVariable=" . $MyString;
    ?>
       I've noticed that the special character '&' residing inside String, throws an error:  #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.
      My first thought was, it has something to do with html entities, but other entities (like <> or ") don't throw any error. Besides, the use of php functions like htmlentities(); or html_entity_decode(); doesn't make any difference in this case:
    print "MyVariable=" . htmlentities($MyString);
    or
    print "MyVariable=" . html_entity_decode($MyString);
      I've also noticed that characters like '%', '^', '+' don't show up at all;
      What does it mean? Any ideas?
      Reagards.

    Thank You 'moccamaximum'.
    Ok. So here is the solution (php function posted by 'moccamaximum' does the trick):
    AS3:
    var MyImportedString:String;
    var variables_page_text:URLVariables = new URLVariables();
    var varSend_page_text:URLRequest = new URLRequest("MyPHP.php");
    varSend_page_text.method = URLRequestMethod.POST;
    varSend_page_text.data = variables_page_text;
    var varLoader_page_text:URLLoader = new URLLoader;
    varLoader_page_text.dataFormat = URLLoaderDataFormat.VARIABLES;
    varLoader_page_text.addEventListener(Event.COMPLETE, var_comp_page_text);
    varLoader_page_text.load(varSend_page_text);
    function var_comp_page_text(event:Event):void {
        MyImportedString =  event.target.data.MyVariable;
         trace(MyImportedString);        // Output:  some text &%^+
    php:
    <?php
    header('Content-Type: text/html; charset=utf-8');
    $MyString = "some text &%^+";
    print "MyVariable=" . flash_encode($MyString);
    function flash_encode($string){
         $string = rawurlencode(utf8_encode($string));
         $string = str_replace("%C2%96", "-", $string);
         $string = str_replace("%C2%91", "%27", $string);
         $string = str_replace("%C2%92", "%27", $string);
         $string = str_replace("%C2%82", "%27", $string);
         $string = str_replace("%C2%93", "%22", $string);
         $string = str_replace("%C2%94", "%22", $string);
         $string = str_replace("%C2%84", "%22", $string);
         $string = str_replace("%C2%8B", "%C2%AB", $string);
         $string = str_replace("%C2%9B", "%C2%BB", $string);
         return $string;
    ?>

  • Finding nr of "new-line"-characters in string

    Hi!
    I looking for a smooth way of achieveing the number of "\n" characters in a string.
    e.g.
    String tmp = "There is a house\n in New Orleans, \n they call the Rising Sun\n";
    This string should return number 3 (three occurrences of the '\n' character.
    How ?
    /Rickard

    I'm not sure if this is the best way to do this but it works ok,
    String tmp = "There is a house\n in New Orleans, \n they call the Rising Sun\n";
    java.util.StringTokenizer st = new java.util.StringTokenizer(tmp, System.getProperty("line.separator"));
    int counter = 0;
    while(st.hasMoreTokens()) {
         st.nextToken();
         counter++;
    }

  • Find special characters in string (using mask)

    Hi all,
    I have the following requirement, perhaps someone has got a hint for me:
    I have got a string of 255 characters.
    I want to realize that this string only contains characters of a "normal" format, like
    a-z, A-Z and numbers.
    Any characters like , - # for example are not allowed and I would like to know, how to check my string.
    How can I achive that? With FIND or SEARCH?
    I am not really familiar with these ABAP KEY WORDS. Can I use masks for example like
    DATA:  no_good type c value '[#,+,*...)
    FIND no_good in STRING
    or something like that?
    Thanks and best regards
    Andreas

    Hi Try the below code:
    data: l_data(10) type c,      
          l_special(10) type c.
    l_data = 'AAA%%AA'.          " You can give your value here
    L_special = '!@#$%^&*()'.     " This need to be maintained wth the char which you don't want
    IF l_data ca l_special.
    WRITE: 'Special'.
    else.
    WRITE: 'Only ALPHA.'.
    ENDIF.
    P.S. - @ Rob, sorry I haven't check you have already given this as CO. Just a doubt, I think we have to use CA here, because we need to check this for each byte level.
    Edited by: Kuntal Nandi on Mar 30, 2009 2:55 PM

Maybe you are looking for

  • Planning function and planning sequence of Design studio new features!!

    Hi Experts Recently I have updated my design studio to 1.3 and happy to see many new updates. Meanwhile i saw some new features add planning function and planning sequence. As per my understanding, Using this features we can enter data at run time. M

  • Disable/Delete Web application on Palm Treo 700p

    I am trying to figure out a way to disable or delete the web application on my palm treo 700p.  Does anyone have a solution for me? Post relates to: Treo 700p (Alltel)

  • Converting a file to JPG looks all messed up

    Hello Everyone, I have this project I am doing for my brothers business. Its called Wilde electric. I have the "W" done, and when I put text beside it, and group it, and save it as a PDF first it looks fine, but when I go from PDF and convert it into

  • DROP PARTITION ONLINE

    Hi, @work we're trying to implement this schema: We've got very high transactional tables... with a huge load of INSERTS on them 24/7; so we decide to partition these tables hourly and remove all the indexes from them. Our problem begins when we issu

  • Agent license for IPCC Express Premium 4.0(3)

    Hello experts! We're currently running IPCC Express Premium 4.0(3) in our environment (I know it's kind of old and we're thinking for a migration soon) but meanwhile, I've been asked to add 4 more agent licenses to our IPCC server to bring 4 more age