I have two string variables ticker and detail. I'm trying to print out the two strings in one line. It just wouldn't work. I've tried so many different ways of doing this. To exclude the possibility of an uninitialized string I tried printing them out in different lines ... this works.
This example works ... except that the output needs to be in one line.
System.out.println(ticker);
System.out.println(detail);
And the output is:
IWM
|0#0.0|0#0.0|0#-4252#386|
GLD
|0#0.0|0#0.0|0#-4704#818|
When I try to put the output into one line in any of many ways, I get only the ticker ... the detail string is just not printed ... not to console or to file. Here are some example code snippets that produce the same result:
Attempt 1:
System.out.println(ticker.concat(detail));
Attempt 2:
System.out.println(ticker+detail);
Attempt 3:
StringBuffer sb = new StringBuffer();
sb.append(ticker);
sb.append(detail);
System.out.print(sb.toString());
Attempt 4:
System.out.print(ticker);
System.out.println(detail);
In all the above attempts, I get the following output ... as if the detail part is ignored:
GOLD
BBL
SI
What could be causing these symptoms? Is there a way to get the two strings printed in one line?
This might be better suited as a comment, but then I couldn't write the code snippet I need to write.
Where do the Strings come from? Are they from a file that might contain some odd control characters? If you're not creating the String yourself, you should examine them to look for embedded vertical carriage returns or other weirdness. Do something like this for both the detail
and ticker
Strings:
for (int i=0; i<detail.length(); ++i)
System.out.println((int) detail.charAt(i));
and see if you get anything in the non-ASCII range.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With