Solved

java concatenation and special characters

Posted on 2011-03-16
2
398 Views
Last Modified: 2012-05-11
a,b,c are variables.
And I want to concatenate them. So I have two related questions:

1- If I do the following, is it gonna process "\n" as a new line character or literally \n? If literally \n, then how can I make it processed as new line character?

2- So I have variable a in my hand. And I want to add b and c as a prefix to a not a suffix. I mean in the beginning of what is in a now. Is this gonna work? If not how can I make it?

a = b + "\n" + c + a;

Open in new window

0
Comment
Question by:Tolgar
2 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 35152114
That newline will be interpreted as an escape sequence so you'll actually get a newline in the String. Print it out and you'll see
0
 
LVL 92

Expert Comment

by:objects
ID: 35152137
1. It will be treated as a new line char. Generally better to use System.getProperty("line.separator") as it will be line seperator for the platform you are running on
2. you can change the order of concatentation however you like
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now