Skip to main content
Announcements
Accelerate Your Success: Fuel your data and AI journey with the right services, delivered by our experts. Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Jcs19
Creator II
Creator II

[resolved] tmap convert string to char

Hello Talend,

I'm trying to convert a string "X" to a character 'x' in tMap
Actually my problem is that when i tried to do (row1.name == "X")?1:0 Talend never reconize "X" and always return 0 whereas there are X in my data.
Thats wierd, maybe its because my string contains only 1 character !
That's why I want to try row1.name == 'X'
My Data : 
0683p000009MCY7.png
My tMap
0683p000009MCdL.png
MS_op is string
test is integer
I also tried to trim and left(row1.name,1)

My output
  0683p000009MCEI.png

Expected output 
X ¦ 1
X ¦ 1
¦ 0
¦ 0
what's wrong !? HALP !!
Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable

Hi,
looks like you're getting tripped up on a bit of subtle java syntax.
to get it to do what you want, you'll need to use the "<String>.equals()" String method instead of "==". 
Java uses "==" to compare object references, not to check if the contents are the same. 
give this a try in your tMap:

"X".equals(row1.name) ? 1 : 0

View solution in original post

3 Replies
Jcs19
Creator II
Creator II
Author

I found a workaround by doing 
(row1.name==null)?0:1
but i really want if row1.name = "X" then 1 else 0
Anonymous
Not applicable

Hi,
looks like you're getting tripped up on a bit of subtle java syntax.
to get it to do what you want, you'll need to use the "<String>.equals()" String method instead of "==". 
Java uses "==" to compare object references, not to check if the contents are the same. 
give this a try in your tMap:

"X".equals(row1.name) ? 1 : 0
Jcs19
Creator II
Creator II
Author

Hi,
looks like you're getting tripped up on a bit of subtle java syntax.
to get it to do what you want, you'll need to use the "<String>.equals()" String method instead of "==". 
Java uses "==" to compare object references, not to check if the contents are the same. 
give this a try in your tMap:

"X".equals(row1.name) ? 1 : 0


Thank you, it works! 
I tried that but i did row1.name.equals("X")?1:0 and i had a null error