I'm a noob to android development and I am trying to split a string multiple times by its multiple line breaks.  the string I'm trying to split is pulled from a database query and is constructed like this:  public String getCoin() {     // TODO Auto-generated method stub     String[] columns = new String[]{ KEY_ROWID, KEY_NAME, KEY_QUANTITY, KEY_OUNCES, KEY_VALUE };     Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null, null, null);     String result = "";      int iRow = c.getColumnIndex(KEY_ROWID);     int iName = c.getColumnIndex(KEY_NAME);     int iQuantity = c.getColumnIndex(KEY_QUANTITY);     int iOunces = c.getColumnIndex(KEY_OUNCES);     int iValue = c.getColumnIndex(KEY_VALUE);      for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){         result = result + /*c.getString(iRow) + " " +*/ c.getString(iName).substring(0, Math.min(18, c.getString(iName).length())) + "\n";     }     c.close();     return result;   result.getCoin reads as this:   alphabravocharlie   I want to split the string at the line break and place each substring into a String Array. This is my current code:  String[] separated = result.split("\n");       for (int i = 0; i &lt; separated.length; i++) {            chartnames.add("$." + separated[i] + " some text" );             }   This gives me an output of:  "$.alpha bravo charlie some text"   instead of my desired output of:  "$.alpha some text, $.bravo some text, $.charlie some text"   Any help is greatly appreciated
6954
I'm trying to split text in a JTextArea using a regex to split the String by \n However, this does not work and I also tried by \r\n|\r|n and many other combination of regexes. Code:  public void insertUpdate(DocumentEvent e) {     String split[], docStr = null;     Document textAreaDoc = (Document)e.getDocument();      try {         docStr = textAreaDoc.getText(textAreaDoc.getStartPosition().getOffset(), textAreaDoc.getEndPosition().getOffset());     } catch (BadLocationException e1) {         // TODO Auto-generated catch block         e1.printStackTrace();     }      split = docStr.split("\\n"); }
3154
I have a string User name (sales) and I want to extract the text between the brackets, how would I do this?   I suspect sub-string but I can't work out how to read until the closing bracket, the length of text will vary.
23579
It's probably beginner question but I'm going through documentation for longer time already and I can't find any solution. I thought I could use implode for each dimension and then put those strings back together with str_split to make new simple array. However I never know if the join pattern isn't also in values and so after doing str_split my original values could break.  Is there something like combine($array1, $array2) for arrays inside of multi-dimensional array?
4322
I have a long line of code that I want to break up among multiple lines. What do I use and what is the syntax?  For example, adding a bunch of strings,  e = 'a' + 'b' + 'c' + 'd'   and have it in two lines like this:  e = 'a' + 'b' +     'c' + 'd'
19032
I have data in a Word table that includes line and paragraph breaks. When I copy the data into Excel, it splits each line and paragraph I want into multiple cells. How do I copy the data to Excel and keep the breaks?
7002
PHP's explode function returns an array of strings split on some provided substring. It will return empty strings when there are leading, trailing, or consecutive delimiters, like this: var_dump(explode('/', '1/2//3/')); array(5) {   [0]=&gt;   string(1) &quot;1&quot;   [1]=&gt;   string(1) &quot;2&quot;   [2]=&gt;   string(0) &quot;&quot;   [3]=&gt;   string(1) &quot;3&quot;   [4]=&gt;   string(0) &quot;&quot; }  Is there some different function or option or anything that would return everything except the empty strings? var_dump(different_explode('/', '1/2//3/')); array(3) {   [0]=&gt;   string(1) &quot;1&quot;   [1]=&gt;   string(1) &quot;2&quot;   [2]=&gt;   string(1) &quot;3&quot; }
87669
Hope someone can help me. I am using c# and I am somewhat new to it. I am loading a text file into my app and splitting the data on "," I am reading part of string into a &lt;list&gt; when the data is read there is a lot of duplicates that vary depending on the txt file that I load.  Can someone tell me how to check the  and remove any and all duplicates that come up. There is no way of knowing what duplicates will show up as there is infinite possibilities that it could be.  Thanks for the help in advance
67860
I'm building an application where I should capture several values and build a text with them: Name, Age, etc.   The output will be a plain text into a TextBox.  I am trying to make those information appear in kind of columns, therefore I am trying to separate them with tab to make it clearer.  For example, instead of having:  Ann 26 Sarah 29 Paul 45   I would like it to show as:  Ann tab 26 Sarah tab 29 Paul tab 45  Any tip on how to insert the tabs into my text?
92395
I want to split a command line like string in single string parameters. How look the regular expression for it. The problem are that the parameters can be quoted. For example like:  "param 1" param2 "param 3"  should result in:  param 1, param2, param 3
2343
I've been using the idiom below for some time now. And it seems to be the most wide-spread, at least on the sites I've visited.  Is there a better/different way to read a file into a string in Java?  private String readFile(String file) throws IOException {     BufferedReader reader = new BufferedReader(new FileReader (file));     String         line = null;     StringBuilder  stringBuilder = new StringBuilder();     String         ls = System.getProperty("line.separator");      try {         while((line = reader.readLine()) != null) {             stringBuilder.append(line);             stringBuilder.append(ls);         }          return stringBuilder.toString();     } finally {         reader.close();     } }
2047
I have a string which is like this:  this is "a test"   I'm trying to write something in Python to split it up by space while ignoring spaces within quotes. The result I'm looking for is:  ['this','is','a test']   PS. I know you are going to ask "what happens if there are quotes within the quotes, well, in my application, that will never happen.
26241
I have the following string array:  var sa = new string[] {"yabba","dabba","doo"};   I can convert it to "yabba, dabba, doo" it using string.Join() but what is the super-cool LINQ way of doing it?  The Join extension method seems promising but for a novice like me very confusing.
106050
Hi I'm pretty new to Stack Overflow so I hope that I'm doing this correctly and that someone out there has the answer I need.  I'm currently coding a program in Java with Eclipse IDE an my question is this:  I need a snippet of code that does the following  It's supposed to get a .TXT file containing text and from that .TXT file  count the number of rows and print it,  count the number of words and print it,  count the number of characters and print it. And finally make a list of the top 10 words used and print that.  Allt the printing is done to system outprintln  I'm pretty new to Java and am having some difficulties.  Anyone out there who can provide me with these lines of code or that knows where i can find them? I want to study the code provided that's how I learn best=)  Thanks to all   Didnt find the edit button sorry...  I Added this to my question:  Hehe it´s an assignment but not a homework assignment ok i see well i could provide what i've done so far, i think im pretty close but it´s not working for me. Is there anything i have missed?  // Class    Tip   import java.io.*; import java.util.*;  class Tip {     public static void main(String [] args) throws Exception     {          String root = System.getProperty("user.dir");            InputStream is = new FileInputStream( root + "\\tip.txt" );         Scanner scan = new Scanner( is );          String tempString = "";         int lines = 0;         int words = 0;         Vector&lt;Integer&gt; wordLength = new Vector&lt;Integer&gt;();         int avarageWordLength = 0;          while(scan.hasNextLine() == true)         {                 tempString = scan.nextLine();                 lines++;         }          is.close();          is = new FileInputStream( root );         scan = new Scanner( is );          while(scan.hasNext() == true)         {                 tempString = scan.next();                 wordLength.add(tempString.length());                 words++;         }          for(Integer i : wordLength)         {                 avarageWordLength += i;         }         avarageWordLength /= wordLength.size();           System.out.println("Lines : " + lines);         System.out.println("Words : " + words);         System.out.println("Words Avarage Length : " + avarageWordLength);          is.close();          } }
3248
I have an ArrayList&lt;String&gt;, and I want to remove repeated strings from it. How can I do this?
99659
I'd like to split strings like these  'foofo21' 'bar432' 'foobar12345'   into  ['foofo', '21'] ['bar', '432'] ['foobar', '12345']   Does somebody know an easy and simple way to do this in python?
34084
As the title says, is there an easy way to output two columns to the console in Java?  I'm aware of \t, but I haven't found a way to space based on a specific column when using printf.
96279
I am using multicol to make a two-column document using the book document class. I have a long tabular that I want to break where the page breaks and then continue in the next column.  I could split it into two tables, but I want their width and such to be the same. I've tried with longtable but can't get it to work.  I basically want the table to split and arrange itself into two columns just like normal text does.  Edit: Sorry for the lack of information. With just 1 column it works fine with longtable, but when I use multicols it breaks down and just continues outside the page. I also get an error while compiling.     Package longtable Error: longtable not in 1-column mode.   This is a simplification of my code:  \documentclass[11pt,a4paper]{article}  \usepackage{multicol} \usepackage{longtable}  \begin{document}  \begin{multicols}{2}  \begin{longtable}{ccc} Header of first column &amp; Header of second column \\ \endhead Table cell 1, 1 &amp; Table cell 1, 2 \\ Table cell 2, 1 &amp; Table cell 2, 2 \\ Table cell 1, 1 &amp; Table cell 1, 2 \\ ... ... \end{longtable}  \end{multicols}  \end{document}     I hope this is enough information. Any thoughts?