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

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Karuetl
Creator II
Creator II

Substring in Talend

22.33.442.555.0

 

Please help me to get each value separated which is separated by dot 

 

ip1 = 22

ip2 = 33 

ip3 = 442

ip 4 = 555

Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable

You are dealing with String data (text). You need to convert it to an Integer before you can carry out numeric calculations with it. You need to "cast" your String values to int values. Take a look here: https://www.mkyong.com/java/java-convert-string-to-int/

 

But in your scenario you need to do something like this....

 

Integer.parseInt(((String[])Var.var1)[0]) * 16777216

This was actually a different question to the titled question. You should have really raised a different question as it can get confusing when multiple questions are raised under a misleading title. 

View solution in original post

10 Replies
TRF
Champion II
Champion II

Karuetl
Creator II
Creator II
Author

In a file i have data as below , it is comma delimited .  

111.5689.7.0,9.56.783.21,"XX","05","Glen","5004"

 

But the first column is 111.5689.7.0 so i need to get each value which is separated by dot 

Anonymous
Not applicable

You can use a basic Java String method for this called "split". It is described here....

https://docs.oracle.com/javase/9/docs/api/java/lang/String.html#split-java.lang.String-

 

But as an example, if your column is called "value" and your row is called "row1", you would use it like this....

String[] splitVals = row1.value.split("\\.");

You can then retrieve the values using the String[] like below....

String firstToken = splitVals[0];
String secondToken = splitVals[1];
String thirdToken = splitVals[2];
Karuetl
Creator II
Creator II
Author

I am trying to achieve using tmap component

Karuetl
Creator II
Creator II
Author

basically trying to get the position number of the nth occurence of the character in a string 

 

example 

111.5689.7.0

 

first dot should return position = 4

second dot should return  position =  9

third dot should return position = 11

Anonymous
Not applicable

The method I gave you will work. You do not need to know where the "." is. In a tMap variable (of class Object), out this code....

row1.value.split("\\.") 

Then in your tMap output table, retrieve the values in their respective columns like this...

((String[])Var.myObjectVariable)[0] 
((String[])Var.myObjectVariable)[1] 
((String[])Var.myObjectVariable)[2] 
((String[])Var.myObjectVariable)[3] 
Karuetl
Creator II
Creator II
Author

Hi 

 

After getting each value i tried below , but compilation failed 

Detail Message: The operator * is undefined for the argument type(s) String, int

 

(((String[])Var.var1)[0] * 16777216) + (((String[])Var.var1)[1] * 65536) + (((String[])Var.var1)[2] * 256 ) + (((String[])Var.var1)[3]) 

Anonymous
Not applicable

You are dealing with String data (text). You need to convert it to an Integer before you can carry out numeric calculations with it. You need to "cast" your String values to int values. Take a look here: https://www.mkyong.com/java/java-convert-string-to-int/

 

But in your scenario you need to do something like this....

 

Integer.parseInt(((String[])Var.var1)[0]) * 16777216

This was actually a different question to the titled question. You should have really raised a different question as it can get confusing when multiple questions are raised under a misleading title. 

Karuetl
Creator II
Creator II
Author

Hi 

 

I tried but result is not correct 

example 

217.233.0.0

 

217 * 16777216 = 3640655872

 

but output from talend is as =  -654311424