Discussions
Categories
- 196.7K All Categories
- 2.2K Data
- 235 Big Data Appliance
- 1.9K Data Science
- 449.9K Databases
- 221.6K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 549 MySQL Community Space
- 478 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3K ORDS, SODA & JSON in the Database
- 532 SQLcl
- 4K SQL Developer Data Modeler
- 186.9K SQL & PL/SQL
- 21.3K SQL Developer
- 295.4K Development
- 17 Developer Projects
- 138 Programming Languages
- 292.1K Development Tools
- 104 DevOps
- 3.1K QA/Testing
- 645.9K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 153 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.1K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 17 Java Essentials
- 158 Java 8 Questions
- 85.9K Java Programming
- 79 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.2K Java SE
- 13.8K Java Security
- 203 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 399 LiveLabs
- 37 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.6K Other Languages
- 2.3K Chinese
- 170 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 230 Portuguese
how to remove charecter  from string?

i try to replace  from my string with this code
mystring=mystring.replaceAll("","");
but it did not work?
Answers
-
Works fine for me.
public static void main(String[] args)
{
String str = "asffass".replaceAll("", "");
System.out.print(str);
}
-
but it did not work?
If you want help with code you have to POST THE CODE.
Standard Java exceptions NEVER say 'did not work' - they ALWAYS provide an exception number and message.
-
Exception :unmmaped charachter
private List<Card> ankiConvert(File ankiLesson) throws UnsupportedEncodingException{
int i=1;
List<Card> notes=new ArrayList();
Connection conn = null;
Statement query=null;
try {
// db parameters
String url = "jdbc:sqlite:"+ankiLesson.getAbsolutePath();
// create a connection to the database
try{
conn = DriverManager.getConnection(url);
}catch(Exception e){
System.out.println("Connection to SQLite has been established.");
}
query=conn.createStatement();
String sql="SELECT flds,sfld FROM 'notes'";
ResultSet rs=query.executeQuery(sql);
while(rs.next()){
org.jsoup.nodes.Document doc = Jsoup.parse(rs.getString("flds"));
org.jsoup.nodes.Document doc1 = Jsoup.parse(rs.getString("sfld"));
String front=doc1.text();
String back=doc.text().replaceAll("","").replace(front,"");
String image=doc.getElementsByTag("img").attr("src");
Card card=new Card();
card.setId(String.valueOf(i));
card.setFrontside(front.trim().replaceAll("(\\[)(.*)|(\\()(.*)|(\\{)(.*)",""));
card.setBackside(back.trim().replaceFirst("(/.*/)",""));
card.setLevel("0");
card.setTesthit("0");
card.setChapter("All");
if(image!=null){
card.setImg(image);
}
notes.add(card);
i++;
}
rs.close();
} catch (SQLException e) {
System.out.println(e.getMessage());
} finally {
try {
if (conn != null) {
conn.close();
}
} catch (SQLException ex) {
System.out.println(ex.getMessage());
}
}
return notes;
}
-
It is difficult to identify which line is throwing exception.... when we do not have access to your 3rd party libraries.
Exception :unmmaped charachter
May be it is useful to identify the issue, if you could paste the full exception trace.
One more thing, IMHO, it is always pays to write readable code when it comes to maintainable code.
Normally, I avoid chaining method calls.
String back=doc.text().replaceAll("","").replace(front,"");
instead,
String back = doc.text();
back = back.replaceAll(.....); // side note: this could throw NPE if back is null.
back = back.replace(....);
This allows me to step over line by line using the debugger and identify what is being returned when troubleshooting.
-
I think you missed reading this part of what I said:
Standard Java exceptions NEVER say 'did not work' - they ALWAYS provide an exception number and message.
The code you posted pretty much says you do NOT care about what exceptions may occur - and that processing should just continue no matter what happens:
try{ conn = DriverManager.getConnection(url); }catch(Exception e){ System.out.println("Connection to SQLite has been established."); } query=conn.createStatement();
Really?
Even if 'getConnection' raises an exception you just want to go ahead and try to create a statement and continue processing the rest of the code?
You should ONLY capture exceptions if you plan to handle them.
You code has multiple exception blocks and NONE OF THEM actually handle an exception.
} catch (SQLException e) { System.out.println(e.getMessage()); } finally { try { if (conn != null) { conn.close(); } } catch (SQLException ex) { System.out.println(ex.getMessage()); } }
Get rid of ALL of those exception handlers so you can see the actual exceptions that occur and get the information Java provides about exactly WHERE they occur.
Post the actual stack trace that Java provides - it will show the FULL list of events that are happening.
Then start troubleshooting your problem by examining EVERY STEP of the code so you can see what it does
Don't underestimate the importance of what mNem said:
String back=doc.text().replaceAll("","").replace(front,"");
That contains THREE different statements jammed together on one line. That makes it difficult to know which of them, if any, are causing an exception.
If that one line causes a problem it could be the '.replace', the 'replaceAll' or even the 'doc.text()'. Either the 'doc' or the 'front' could be null or problematic.
Write SIMPLE code so you know what the code does. Then you can worry about taking shortcuts and trying to write complex, single-line statements.
Then if you still have trouble identifying the actual line with a problem add a try .. except block around every line until you find the one throwing the exception.
Then examine EACH AND EVERY variable using a debugger (e.g. NetBeans) to make sure they have the value you expect.
Until you remove those garbage exception handlers and post the actual exception stack trace (printStackTrace) we can't really help.