Most of the times while dealing with the Strings in the Java many of us encountered this kind of situation ... the best solution I follow for this is as follows.
Case study : You have some informatrion in DB wich looks like the below
Table name : Merchant
Columns : Merchantid(Number), Merchantname(varchar)
Sample Data : 10001 Best Buy
10002 Circuit city
10003 Macy's
10004 Toy's R us
10005 GK\nGB's
In application we are going to display this kind of data ...so assuming that we are able to get all these in array from DB and going to display like the below..
for ( int i = 0 ; left != null && i <> {
tempObj = (Hashtable)left.get(i);
leftMid += "'" + tempObj.get("marchantid").toString() + "'";
leftMname += "'" + (tempObj.get("marchantname").toString()) + "'" ;
if (i < (left.size()- 1) ){
leftMid += ",";
leftMname += ",";
}
}
Then sure the data will not show the rows
10003 Macy's
10005 GK\nGB's
properly ...they may shown as
10003 Macy
10005 GK GB
Most of the case it may throw error also in such cases just write small Java script function like the below and use this function to replace few charecters to show the coloumns as like in the DB
Java script function will be ...
private String replaceSpecial(String input){
if(input.indexOf("\\") != -1)
input = input.replaceAll("\\\\", "\\\\\\\\");
if(input.indexOf("'") != -1)
input = input.replaceAll("'", "\\\\\'");
return input;
And now change the above for loop code as below
for ( int i = 0 ; left != null && i <> {
tempObj = (Hashtable)left.get(i);
leftMid += "'" + tempObj.get("marchantid").toString() + "'";
leftMname += "'" + replaceSpecial(tempObj.get("marchantname").toString()) + "'" ;
if (i < (left.size()- 1) ){
leftMid += ",";
leftMname += ",";
}
}
HTH ...
Saturday, November 22, 2008
//
Labels:
Java
//
0
comments
//
0 comments to "How to replace esacape(\n \t) charecters and ' charecter in java"
Popular Posts
-
The best solution to know about these init levels is to understand the " man init " command output on Unix. There are basically 8...
-
How to Unlock BSNL 3G data card to use it with Airtel and Vodafone Model no : LW272 ? How to unlock BSNL 3G data card( Model no : LW272 )us...
-
How to transfer bike registration from one State to other (Karnataka to Andhra)?? Most of us having two wheelers purchased and registered in...
-
ఓం శ్రీ స్వామియే శరణం ఆయ్యప్ప!! Related posts : Trip to Sabarimala - Part 1 Trip to Sabarimala - Part 2 Ayappa Deeksha required things...
-
Following are some of interesting blogs I found till now ...please comment to add your blog here. Blogs in English : http://nitawriter.word...
Popular posts
- Airtel and vodafone GPRS settings for pocket PC phones
- Andhra 2 America
- Ayyappa Deeksha required things
- Blogs I watch !
- Captions for your bike
- DB2 FAQs
- Deepavali Vs The Goddes of sleep
- ETV - Dhee D2 D3
- Evolution of smoking in India Women
- How to make credit card payments?
- init 0, init 1, init 2 ..
- Java-J2EE interview preparation
- mCheck Application jar or jad download
- My SQL FAQs
- My Travelogues
- Old is blod - New is italic
- Online pay methids for credit cards
- Oracle FAQs
- Pilgrimages
- Smoking in Indian Women
- Technology Vs Humans
- Twitter feeds for all Telugu stars on single page.
- Unix best practices
- Unix FAQs
Buffs ...
Tags
Powered by WidgetsForFree
Archives
-
▼
2008
(132)
-
▼
November
(14)
- Mayhem in Mumbai - Nov 26, 2008 to Nov 29, 2008
- where is ldd installed in HP unix?
- Customs in work ..found in eenadu daily
- How to replace esacape(\n \t) charecters and ' cha...
- Facing error like this ? : bad interpreter: No suc...
- Educational blog Award ... For making everyone aro...
- Acts can win the hearts ...Friend
- where can I find pmon, smon ...oracle services in ...
- If love becomes marriage ?? ( ప్రెమే పెళ్ళయుతే ?? )
- Harivarasanam ... song meaning and Mp3 downlaod
- How to see hardware details like name and type of ...
- Solaris 10 Zones Vs Solaris 10 physical server
- Ayyappa Deeksha - Required things - Total ayyappa ...
- యువతా!!! బ్లాగ్ అంటె?( Youth!!! blog means? ) - In...
-
▼
November
(14)
Post a Comment
Whoever writes Inappropriate/Vulgar comments to context, generally want to be anonymous …So I hope U r not the one like that?
For lazy logs, u can at least use Name/URL option which doesn’t even require any sign-in, The good thing is that it can accept your lovely nick name also and the URL is not mandatory too.
Thanks for your patience
~Krishna(I love "Transparency")