on 08-20-2007 10:49 AM
Hi Experts,
I have to convert String from "7,00" to "7.00". I tried using replace funtion. However it is not working.
The code is as below. Am I supposed to use some different Java function?
IPrivateTimesheetView.ICategoriesElement categoryElement;
String wbs ="h";
double d =0;
String sum_hrs ="";
for (int i=0 ; i<wdContext.nodeWorklist().size() ; i++){
wdContext.nodeWorklist().setLeadSelection(i);
categoryElement = wdContext.createCategoriesElement();
wbs = wdContext.currentWorklistElement().getReciever_Wbs_Element();
sum_hrs = wdContext.currentWorklistElement().getSum_Hours();
sum_hrs = sum_hrs.replace(",",".");
if( sum_hrs != null && sum_hrs.trim().length()>0)
d = Double.parseDouble(sum_hrs) ;
categoryElement.setCategoryText(wbs);
categoryElement.setSeries1Value(d);
wdContext.nodeCategories().addElement(categoryElement);
wbs = "";
The error message is
java.lang.NoSuchMethodError: java.lang.String.replace(Ljava/lang/CharSequence;Ljava/lang/CharSequence;)Ljava/lang/String;
at com.sastech.app.models.TimesheetView.onActionFindRecord(TimesheetView.java:253)
at com.sastech.app.models.wdp.InternalTimesheetView.wdInvokeEventHandler(InternalTimesheetView.java:365)
at com.sap.tc.webdynpro.progmodel.generation.DelegatingView.invokeEventHandler(DelegatingView.java:87)
at com.sap.tc.webdynpro.progmodel.controller.Action.fire(Action.java:67)
at com.sap.tc.webdynpro.clientserver.window.WindowPhaseModel.doHandleActionEvent(WindowPhaseModel.java:420)
... 26 more
Can you please help me?
Regards,
S
Hi,
If you want to pass string then better use replaceAll instead of replace.
Ashutosh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The issue got sorted out by using replaceAll in place of replace. Thanks every one who has replied to the thread for the help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Stuart,
see api here http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#replace(char,%20char)
Hovewer your sum_hrs.replace(",","."); seems to be ok. Please, try to execute the replace outside the "for", probabily you have any strange value.
Hope this help.
Vito
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi.
The reason is String's class replace method take char as an argument while you are passing String literals as a argument. As an example:
String str = "7,00";
str = str.replace(',','.');
System.out.println(str);
Regards,
Nitin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.