StringTokenizer class problem with strings in double quotes
Hello Technocrats,
I have a problem with tokenizing following string enclosed in (). (abc," India, Asia", computer engineer). My separator is ",", thus StringTokenizer class gives me 4 tokens namely abc, "India, Asia" and computer engineer. But I require that String in double quotes should be a single token. How to achieve this using StringTokenizer class? Or is there any other way?
Thanks in advance.
Try
String[] str="abc,\" India, Asia\",computer engineer".split(",",1);
for(String s: str)
System.out.println(s);
}Thanks.
Similar Messages
-
Binds with string containing double quotes
Hello there,
I have the following SELECT statement which is run from a Delphi application :
SELECT Customer, Last_Name
FROM Customer
WHERE UPPER(Last_Name) LIKE :last;
:last has the string value of Smith"a".
Is there a problem with binds and strings wich contain double quotes?.
If so, how can I fix this problem?
Thanks,
MiaHi
There is no problem in this example. Content of bind variable is not part of syntc checking, so you can have any characters.
Regards
null -
I am new to Java Programming.
I have a line of code that works and does what is supposed to.
faceData.getProfile("Lisa").removeFriend("Curtis");
If I assign the strings to variables such as-
String name = "Lisa";
String fName = "Curtis";
and then plug those into the same line of code, it does not work
faceData.getProfile(name).removeFriend(fName);
What could be causing the problem?
I even added some lines to print out what is stored in the variables to verify that they are what they should be, but for some reason the variables do not work while putting the strings in quotes does. Any ideas?I guarantee that something about your assertions are incorrect. Those variables are either not equal to the values you claim, or something else is going on. But it's not a problem with string variables versus string constants.
Edit: My best guess in lack of a real example from you, is that the strings in question have non-printable characters in them, such as trailing spaces or line feeds. -
Little problem with Strings.
I have an little problem with Strings, i make one comparision like this.
String nombre="Javier";
if( nombre.equalsIgnoreCase(output.getStringValue("CN_NOMBRESf",null)) )
Wich output.getStringValue("CN_NOMBRESf",null) is "Javier" too, because I display
this before and are equals.
What I do wrong?.
You are actually making your users key in things like
"\026"? Not very user-friendly, I would say. But
assuming that is the best way for you to get your
input, or if it's just you doing the input, the way to
change that 4-character string into the single
character that Java represents by '\026', you would
use a bit of code like this:char encoded =
(char)Integer.parseInt(substring(inputString, 1),
16);
DrClap has the right idea, except '\026' is octal, not hex. So change the radix from 16 to 8. Unicode is usually represented like '\u002A'. So it looks like you want:String s = "\\077";
System.out.println((char)Integer.parseInt(s.substring(1), 8));Now all you have to do is parse through the String and replace them, which I think shouldn't be too hard for you now :) -
Problem with String to Int conversion
Dear Friends,
Problem with String to Int conversion
I am having a column where most of the values are numeric. Only 4 values are non numeric.
I have replaces those non numeric values to numeric in order to maintain the data type.
CASE Grade.Grade WHEN 'E4' THEN '24' WHEN 'E3' THEN '23' WHEN 'E2' THEN '22' WHEN 'E1' THEN '21' ELSE Grade.Grade END
This comes the result as down
Grade
_0_
_1_
_10_
_11_
_12_
_13_
_14_
_15_
_16_
_17_
_18_
_19_
_2_
_20_
_21_
_22_
_23_
_24_
_3_
_4_
_5_
_6_
_7_
_8_
_9_
Refresh
Now I want to convert this value to numeric and do some calculation
So I changed the formula as below
cast (CASE Grade.Grade WHEN 'E4' THEN '24' WHEN 'E3' THEN '23' WHEN 'E2' THEN '22' WHEN 'E1' THEN '21' ELSE Grade.Grade END as INT)
Now I get the following error
View Display Error
_ Odbc driver returned an error (SQLExecDirectW)._
Error Details
Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
_State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 17001] Oracle Error code: 1722, message: ORA-01722: invalid number at OCI call OCIStmtFetch. [nQSError: 17012] Bulk fetch failed. (HY000)_
SQL Issued: SELECT cast ( CASE Grade.Grade WHEN 'E4' THEN '24' WHEN 'E3' THEN '23' WHEN 'E2' THEN '22' WHEN 'E1' THEN '21' ELSE Grade.Grade END as Int) saw0 FROM "Human Capital - Manpower Costing" WHERE LENGTH(CASE Grade.Grade WHEN 'E1' THEN '20' WHEN 'E2' THEN '21' WHEN 'E3' THEN '22' WHEN 'E4' THEN '23' ELSE Grade.Grade END) > 0 ORDER BY saw_0_
Refresh
Could anybody help me
Regards
Mustafa
Edited by: Musnet on Jun 29, 2010 5:42 AM
Edited by: Musnet on Jun 29, 2010 6:48 AMDear Kart,
This give me another hint, Yes you are right. There was one row which returns neither blank nor any value.
I have done the code like following and it works fine
Thanks again for your support
Regards
Code: cast (CASE (CASE WHEN Length(Grade.Grade)=0 THEN '--' ELSE Grade.Grade END) WHEN 'E4' THEN '24' WHEN 'E3' THEN '23' WHEN 'E2' THEN '22' WHEN 'E1' THEN '21' when '--' then '-1' ELSE Grade.Grade END as Int) -
Transforming to HTML and problems with incorrect entities for quotes
Hello,
I have a seemingly fairly simple problem, I have a DOM tree which I would like to convert to HTML.
This works fine, also for special characters like umlauts - they are escaped with the correct html entities.
However single and double quotes are not escaped at all. Do I need to define custom entities for that?
Sample code:
package generaltests;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import java.io.*;
public class XmlTransform {
public static void main(String args[]) {
try {
DocumentBuilderFactory dbfac =
DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
Document doc = docBuilder.newDocument();
//<QBXML>
Element root = doc.createElement("ROOT");
doc.appendChild(root);
Element text = doc.createElement("TEXT");
root.appendChild(text);
text.appendChild(doc.createTextNode("Test text\n< With special character ' and umlaut �"));
// Transformation
TransformerFactory transfac = TransformerFactory.newInstance();
Transformer trans = transfac.newTransformer();
trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
trans.setOutputProperty(OutputKeys.METHOD, "html");
trans.setOutputProperty(OutputKeys.ENCODING, "US-ASCII");
//create string from xml tree
StringWriter sw = new StringWriter();
StreamResult result = new StreamResult(sw);
DOMSource source = new DOMSource(doc);
trans.transform(source, result);
System.out.println(sw.toString());
} catch (Exception e) {
}Output is (the first left bracket in the second line is actually escaped correctly and only transformed to < in this post):
<ROOT><TEXT>Test text
< With special character ' and umlaut ö</TEXT></ROOT>Edited by: tzu22 on Apr 16, 2008 1:44 AM
Edited by: tzu22 on Apr 16, 2008 1:50 AM& quot; and & apos; have to be used for attribute values. For text nodes, " and ' can be used as ordinary characters.
Edited by: Alain_COUTHURES on Apr 16, 2008 8:32 AM -
Problems with java.lang.Double in a Pojo
Hi!
I'm getting some problems with a Double (wrapper class) in a sub-report related with a Pojo.
The exception has more than 100 lines.
It's starts with:
at com.crystaldecisions.sdk.occa.report.application.ds.a(Unknown Source)
at com.crystaldecisions.sdk.occa.report.application.ReportSource.a(Unknown Source)
at com.crystaldecisions.sdk.occa.report.application.ReportSource.a(Unknown Source)
at com.crystaldecisions.sdk.occa.report.application.PrintOutputController.if(Unknown Source)
at com.crystaldecisions.sdk.occa.report.application.PrintOutputController.export(Unknown Source)
at com.crystaldecisions.sdk.occa.report.application.PrintOutputController.export(Unknown Source)
at br.inf.teorema.javautils.util.CrystalReportsUtils.export(CrystalReportsUtils.java:520)
Caused by: com.crystaldecisions.sdk.occa.report.application.b6: Valor nulo inesperado localizado para o membro Produto.getAliquotaICMS. (UNEXPECTED NULL VALUE ... )
at com.crystaldecisions.sdk.occa.report.application.b6.a(Unknown Source)
at com.crystaldecisions.sdk.occa.report.application.de.a(Unknown Source)
at com.crystaldecisions.sdk.occa.report.application.de.if(Unknown Source)
at com.crystaldecisions.sdk.occa.report.application.de.getDouble(Unknown Source)
and ends with:
[JRCCommunicationAdapter] detected an exception: Erro inesperado do conector do banco de dados (UNEXPECTED ERROR WITH DATABASE CONNECTOR )
at com.crystaldecisions.reports.queryengine.Row.char(Unknown Source)
at com.crystaldecisions.reports.queryengine.Row.getValue(Unknown Source)
at com.crystaldecisions.reports.datalayer.a$d.getValue(Unknown Source)
at com.crystaldecisions.reports.saveddata.saveddata.SavedData.a(Unknown Source)
at com.crystaldecisions.reports.saveddata.a.a(Unknown Source)
at com.crystaldecisions.reports.saveddata.a.a(Unknown Source)
at com.crystaldecisions.reports.basicdataengine.a.p(Unknown Source)
at com.crystaldecisions.reports.basicdataengine.a.a(Unknown Source)
It occurs when my Double has null value. When I put "0.0", there are no problems.
Anyway, in specifics contexts, null != 0.0.
I think it's a bug. Someone encountered the same problem?Sorry for my insistence, but this problem occurs only for me?
I will explain better.
If I have a report that show the value of a Double field, the getter method should be:
public Double getMyField() {
return myField;
But if myField == null, I can't generate the report.
So, I did:
public Double getMyField() {
if (myField == null) {
myField = 0.0d;
return myField;
I wish don't need to do this correction in getter method.
CR do not works this way with Double?
I have tested, and String works fine. -
Extracting string inside double quote
Hi,
In perl this is really easy, but I can't get it to work correclt in java. I'm trying to extract a string that is in double quotes following a keyword...
String: SRCH base="o=answer" filter="me" attrs=ALL
I want to extract the first quoted value after "SRCH base="
In perl I used: / SRCH base=\"(.*)\" /i
In java I'm using: " SRCH base=\"(.*)\" "
The problem is that it doesn't stop after hitting the second quote. So I get this result:
o=answer" filter="me
Notice that it stopped matching after hitting the third quote. Weird.
I know this is probably really simple, but I'm stumped.
Thanks,
MarkI guess if you wrote a regex that matches any string
that starts with ", ends with ", and has anything in
between you could use a Matcher to find each
occurrence, but I don't regex enough to write it :)[url #" style="display: block; background-image: url('http://www.shanghaiist.com/attachments/shang_neil/bat-signal-edit.jpg'); width: 325px; height: 217px] -
Problems with the richTextEditor and quotes
Hello
I'm having problems with quote chars and the richText
control's htmlText. When users enter quotes into the richTextEditor
control. The quotes breaks the HTML text, meaning it's no longer
well formatted. Is there an escape char that I need to use. Or do I
need to force some kind of refresh on the control prior to using
the htmlText string?I have been using RTE in a content management system and
found a need to replace non-standard quote characters with proper
UTF-8 character counterparts. Curly quotes in particular are
problematic. Use a replace function to substitute non-standard for
standard characters. -
Could not find the main class - Problem with Webservice-Access
Hello Everybody,
I'm having serious Problems with accessing a WebService (Tomcat-Axis) per executable jar-File.
I constructed a simple GUI with 3 Textboxes 1 Button and 1 Resultbox.
I use eclipse so it was no Problem to simple generate the Backgroundclient by Processing the .wsdl-File of the WS.
Now I do this:
Head_tServiceLocator serviceLocator = new Head_tServiceLocator();
Head_t service = serviceLocator.getRPCCall();
RPCCallSoapBindingStub Head_t = (RPCCallSoapBindingStub) service;and use the Webservice like an Object.
All this works very well.
Now the Problem:
Head_t service = serviceLocator.getRPCCall();this Line has to throw a ServiceException.
If i add a try-catch Block to Process the Message JAVA tells me after i exported to JAR (with Manifest-stuff and so on) and double Click on the JAR the following :
Could not find the main Class - Program will exit.
And if i add a throws Declaration to the Methodheader it tells me:
Fatal Exception Occured - Program will exit
But if i Comment out that Line at least the GUI is being displayed (so it DOES find the main-Class). But then of course the Webservice won't be accessed.
All the JARs needed (axis.jar, commons-discovery.jar and so on) are in the same Directory as the Webservice-Client.jar
Please Help me.
Greets,
ZapI am not done any typing mistake while creating the jar file i already followed the suggestion that you have mentioned but still the same error .
This is my MANIFEST.MF file created under META-INF folder
Manifest-Version: 1.0
Class-Path: qtjambi-4.4.3_01.jar qtjambi-win32-msvc2005-4.4.3_01.jar
Created-By: 1.5.0 (Sun Microsystems Inc.)
Main-Class: Ui_MainWindow
When i extracted the app.jar following this i got
1. META-INF folder inside that MAINFEST.MF file the contents i have already placed above
2. qtjambi-4.4.3_01.jar
3. qtjambi-win32-msvc2005-4.4.3_01.jar
4. Ui_MainWindow.class
Please tell me whats wrong in that i can also give you the app.jar file please let me know the email id .. -
Problem with String Parameter in Command
I'm running CR XI. I have a report that I want to change the command to use a parameter rather than an hard-coded number that I used for testing. The text of the SQL is:
select j.instrument_type,j.cost_type_cd,j.customer,j.bs, j.product,j.del_pd, j.bl_num, j.date2,j.match,j.jrnl_ref,j.mot_name,
j.tank_name, j.trade_num , j.date3, j.volume, j.invoice, j.trade_price,
j.mrkt_price, j.book_pl, j.pl, o.strategy_name, j.snapshot
from JE_TABLE_{?TName} j, ORG_STRATEGY o
where j.STRATEGY in (select o.external_ref from org_strategy o where o.strategy_name='{?StratName}')
and j.strategy=o.external_ref and j.cost_in_mtm=1
order by j.PL
When I added the '{?StratName}' to the SQL, CR started aslways failing telling me I had an invalid character. So, I changed to double quotes and the error message changed to the expected Oracle error becuase it does nto like double quotes but I did not get the invalid character error.
This is a string parameter so I need the single quotes. What do I need to do to get CR to handle it? I've used this structure before ino other reports and it never objected to the single quotes before.
Could the command just be corrupt?I decided to create a new blank report and added the command as before and then paramterized it. This time there was no problem. It must be that the other command was corrupt.
-
Problem with SQL space and quotes
Hi all,
We have some old generated java code which includes sql statements like:
select count ("ID") from SUBSCRIBER;
In our production database (10.2.0.2) this SQL works. In our test database (which is also 10.2.0.2), this SQL causes ORA-00942: table or view does not exist error. However, on the same test database, the following variations work:
SELECT count ("ID") from SUBSCRIBER;
select count (ID) from SUBSCRIBER;
select count("ID") from SUBSCRIBER;
I cannot change the original java code and I must configure our test database to execute the same SQL. I suspect this behaviour is caused by some oracle init parameters (maybe the "compatible" parameter?). Does anybody have any idea how this problem can be solved?
Best regards,
SerkanCTable or View does not exist means that the user who is running your query can not see the table.
The problem is that your user does not have appropriate privileges. If you don't specify the schema_name, you are relying on a synonym existing.
Finally, some "Bright Spark" may have created the table using double quotes with the table_name not being entirely in uppercase.
P.S. If your code was in a procedure you would find this error at compile time.
So:
i) find out which user is running the java code
ii) connect as that user in sqlplus and issue the same statement
You should get an error.
Determine if a private or public synonym exists (all_synonyms data dictionary view).
This has nothing to do with compatibility. -
Hi,
I am new to Java,
I want to insert a string in database but it should not have double quotes.
e.g i want to insert string TJ2003W.
But when we declare this as string it is surronded by double quotes.
Pls help reagrding this.Hi,
I am new to Java,
I want to insert a string in database but it should
not have double quotes.
e.g i want to insert string TJ2003W.
But when we declare this as string it is surronded by
double quotes.
Pls help reagrding this.Hi,
Strings are declared by double quotes. and when u insert them in database, just add the variable for string.
Please elaborate your problem more. -
As mentioned above I have just downloaded OSX Maverick to my iMac. I am now having a lot of problems with iCloud. I get the message that "This iMac can't connect to iCloud because of a problem with, and then it goes on to quote my e-mail address. It then says to open iCloud preferences to fix this problem.
I do this and no matter what I seem to do this message continues to return.
Can anybody explain how to resolve this problem (please bear in mind that I am noy very computer literate).
Many thanks
MikeHello John
Sorry I haven't got back to you sooner.
Thanks very much for your help, your solution solved my problem.
Thanks again and kind regards
Mike -
Problem with String in a Vector
I'm making a small hangman game. And I got a problem with putting words in a Vector... This is the code... Can someone tell me what I'm doing wrong?
// First I define it.
Vector Words;
// Then add the words
Vector Words = new Vector();
Words.add(new String("HELLO"));
Words.add(new String("GOOD BYE"));
// When I try to get a string from the Vector I use this.
// The program compiles but when I try to run it I get NullPointerExeption here
W = (String) Words.elementAt(0);Not sure since I cant see all of your code but looks like this might be your problem:
// First I define it.
Vector Words; //<-- here you define a Vector named Words that is null
// Then add the words
Vector Words = new Vector(); //<-- here you define another vector named Words that holds a reference to a new Vector. This is a different reference than the one created above so you should probably remove the "Vector" part from the beginning of this line. Is this a local variable to a method and the one before is a global variable?
//Here you probably access the locally created Words vector which is initialized
Words.add(new String("HELLO"));
// When I try to get a string from the Vector I use this.
// The program compiles but when I try to run it I get NullPointerExeption here
W = (String) Words.elementAt(0); //<--and here my guess is that this statement is inside another method than the one with the local Words vector defined. Thus this one accesses the global Words Vector that is never initalized and is Null. And that gives you the NullPointerException.
So try changing the statement
Vector Words = new Vector();
to
Words = new Vector();
or just remove it totally and move the Vector creation to the place where you introduce the global variable.
Of course I might be totally wrong since I cant see all of your code but that is my guess.
Hope it helps,
-teka
Maybe you are looking for
-
F4 help for a field in alv grid
hello friends, i want to make one of the fields of my alv grid as editable and i want f4 help option also available for it, can v do it, if yes how??? pls explain through code thanks
-
When i am backing up my iPhone, where is it backing up to?
I am trying to bck up my iphone 3GS 16GB onto my Macbook Pro, but i dont know where it is backing it up to? Therefore i am worried i will not be able to access my data when i upgrade my phone. Anyon please help.
-
Keynote Version 6 exports images in nice form, but does not allow you to output only chosen slides. It creates images for every slide! It lets you pick slides 4 and 5 for example, but will send out an image for every slide you have, whether you hav
-
Thin lines appears somtimes in macbook air
HI I just bough Macbook Air 2013 2 weeks ago and i am expesiencing some thin line horizental appearig in my screen for a fraction of a second ... it have happned 5-6 time now.. is somting propblem with hardware ? please help its Macbook Air with 8 G
-
Itunes has 111 albums that are not mine...
My main computer (i.e. where all of the physical files are) is Windows 7. I've turned on home sharing on that computer. Downstairs is a Macbook Air. When opening up iTunes there, it doesn't see my library (it's always been iffy at best), but it's s