Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I have this table and I'm trying to apply a conditional statement to get a boolean to find out if the 5th position of the field DATE is char "/"
I've made it in two steps, first I've applied this statement to get the "/" from the 5th position:
StringHandling.RIGHT(StringHandling.LEFT(row1.DATE,5),1)
That works, but when I add the contitional expression, It doesn't work and all I got are 0:
StringHandling.RIGHT(StringHandling.LEFT(row1.DATE,5),1) == "/" ? 1:0
Could someone help me, please?
Thank you!!
Hello,
== is an operator comparing objects in your example, not their content!
Comparing strings can be made with the .equals() method of the String object :
"/".equals(StringHandling.RIGHT(StringHandling.LEFT(row1.DATE,5),1))?1:0
Or with the .equals method of the Objects object (you may have to import it first) :
Objects.equals("/", StringHandling.RIGHT(StringHandling.LEFT(row1.DATE,5),1))?1:0
You can also use other methods depending on your needs (.compareTo() for example)
Hello,
== is an operator comparing objects in your example, not their content!
Comparing strings can be made with the .equals() method of the String object :
"/".equals(StringHandling.RIGHT(StringHandling.LEFT(row1.DATE,5),1))?1:0
Or with the .equals method of the Objects object (you may have to import it first) :
Objects.equals("/", StringHandling.RIGHT(StringHandling.LEFT(row1.DATE,5),1))?1:0
You can also use other methods depending on your needs (.compareTo() for example)
Thank you!!
By the way, now I'm trying to apply the same rule to determine if the 5th and 6th characters are smaller than 12.
<= 12 (StringHandling.RIGHT(StringHandling.LEFT(row1.DATE,7),2)) ?1:0
Could you please tell me which would be the correct sentence?
Thank you!!
if (StringHandling.RIGHT(StringHandling.LEFT(row1.DATE,7),2)) returns the correct part of the String, and you are sure it will be a number, you may do
Integer.parseInt(StringHandling.RIGHT(StringHandling.LEFT(row1.DATE,7),2))) <= 12
In this case, you can use <= as you are comparing an int primitive with the value 12
Yes, I've tried this sentence, the problem is that not always will be a number, here's an example on which it's "/2":
Then you should test the value before:
First add a tMap variable testValue with this code :
Integer.parseInt(StringHandling.RIGHT(StringHandling.LEFT(row1.DATE,7),2)))
And then use this in your test:
Var.testValue.matches([0-9]+)?Integer.parseInt(Var.testValue)<=12:false
This will test if your substring contains only digits. If yes, this will return if that number is less or equal than 12. If no, this will return false.
I've tried adding the testValue and then executing this sentence:
Var.testValue.matches([0-9]+)?Integer.parseInt(Var.testValue)<=12:false
And I have this error:
Thank you for your time
Of course, I forgot to quote the regex
Var.testValue.matches("[0-9]+")?Integer.parseInt(Var.testValue)<=12:false