Results 1 to 4 of 4
Thread: String composing problem ...
- 11-16-2011, 10:51 AM #1
Member
- Join Date
- Nov 2011
- Posts
- 3
- Rep Power
- 0
String composing problem ...
Hello Friends!
I have problem with String composition. I want to compose a string with a '+' operator. But the result is not what I would expect.
Here is the example: String date = "16" + "." + "11" + "." + " 2011";
I expect to get a string date written in this form: "16.11.2011", but unfortunatelly the result is "16.112011" so the second dot (.) is missing.
Of course, in real program I use variables intead of "16", "11" and "1911" but the problem is the same!
So, where does the problem lie?
I know that I need to write dot character '.' in this shape '\\." when I wish to search for dot character (.) in string or when I need to parse string with dot character. But I don't know for the reason above.
Thank you for your help in advance,
Ernest
- 11-16-2011, 11:36 AM #2
Re: String composing problem ...
first of all you have to use StringBuilder or StringBuffer for concatenations string because an operation plus is so expensive for your performance.
This is correct code. I guess that you miss your dot in another parts your code. Can you show us your code?Java Code:String date = "16" + "." + "11" + "." + " 2011";
Skype: petrarsentev
http://TrackStudio.com
- 11-16-2011, 01:06 PM #3
Member
- Join Date
- Nov 2011
- Posts
- 3
- Rep Power
- 0
Re: String composing problem ...
My original code is bellow. If you use code inside comment /* */ with '-' instead of '.' everything is OK (16.11.2011), but with '.' I get 16.112011 (dot is missing).
public void nastaviIzbranDatumZaPrisotnost(String imeTabelePrisotnost){ //v obliki 'prisotnost2011_10' to metodo kličemo iz
// class JedPulPregledPrisotnostiPoOsebi->public void zgradiSQLQueryZaTiskanje(){
System.out.println("Ime tabele = " + imeTabelePrisotnost);
String temp1 = imeTabelePrisotnost.replaceFirst("prisotnost","");//iz prisotnost2011_10 dobim 2011_10
String[] temp2 = temp1.split("_");
String leto = temp2[0];
String mesec = temp2[1];
izbranoLeto = leto;
izbranMesec = mesec;
/*
izbranDatumZaPrisotnost = "1-" + mesec;
izbranDatumZaPrisotnost = izbranDatumZaPrisotnost + "-";
izbranDatumZaPrisotnost = izbranDatumZaPrisotnost + leto;
*/
izbranDatumZaPrisotnost = "1." + mesec;
izbranDatumZaPrisotnost = izbranDatumZaPrisotnost + ".";
izbranDatumZaPrisotnost = izbranDatumZaPrisotnost + leto;
System.out.println("Date: " + izbranDatumZaPrisotnost);
}
Best regards,
Ernest
- 11-16-2011, 08:45 PM #4
Member
- Join Date
- Nov 2011
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
String Parsing Problem
By jamess in forum New To JavaReplies: 3Last Post: 12-06-2010, 09:59 AM -
Basic string problem, just need to extract two numbers out of string
By gonzoateafly in forum New To JavaReplies: 6Last Post: 12-06-2010, 09:26 AM -
string to negative int problem
By pendulum101 in forum New To JavaReplies: 5Last Post: 11-01-2009, 05:47 PM -
String Problem
By gnomewise in forum New To JavaReplies: 1Last Post: 10-19-2008, 12:37 PM -
problem with using string in if condition
By sireesha in forum New To JavaReplies: 2Last Post: 11-20-2007, 10:40 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks