Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik and ServiceNow Partner to Bring Trusted Enterprise Context into AI-Powered Workflows. Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

replace last character to first on condition

Hi,
I am getting data as 42788.00- and 231249.00- in csv but it is actually -42788.00 and -231249.00.
So how to remove - from last and add uit to first wherever its negative value.
Regards,
Dhruv

Labels (2)
4 Replies
avinashbasetty
Contributor III
Contributor III

Hi Dhruv,
Try this logic using tMap component....
public class Test {
public static void main(String[] args) {
String str="42788.00";
if(str.endsWith("-"))
{
System.out.println("true");
String Str1=str.replace("-", " ");
System.out.println(Str1);
}
else
{
String Str2="-".concat(str);
System.out.println(Str2);
}
}
}
Anonymous
Not applicable
Author

Hi Avinash,
Thanks for your Reply.
But i Am getting attached error while applying your code.
Regards,
Dhruv 
Anonymous
Not applicable
Author

Hi,
I have tried below code and i think this should work.
(StringHandling.RIGHT(row1.Column52,1)="-" ? "-"+StringHandling.EREPLACE(row1.Column52,"-",""): row1.Column52)
but there is one error
"the left hand side assignment must be a variable."
I am not able to understand this error.
Please help me with this.
Regards,
Dhruv
cterenzi
Specialist
Specialist

You're using a single '=' for comparison instead of a '=='.

However, you're comparing strings, so you should be using .equals instead of == for comparison.

e.g. "-".equals(StringHandling.RIGHT(row1.Column52,1)) ? "-"+StringHandling.EREPLACE(row1.Column52,"-","") : row1.Column52