Split

Highlighted
One Star

Split

Hello,

I have this text:

25.815.53.6

And I need to get:

25.8
15.5
3.6

Or this text:

22.816.210.2

And I want to get:

22.8
16.2
10.2

Thank you very much.

Highlighted
Community Manager

Re: Split

I have had to guess at your requirement here. I guessed the following....

1) Every number will have a decimal point

2) Every decimal point will be followed by 1 decimal digit

 

If those guesses are correct, this code will work in a tJava....

 

String foo = "25.815.53.622.816.210.2";

while(foo.indexOf('.')>-1){
	int position = foo.indexOf('.')+2;
	String value = foo.substring(0,position);
	foo = foo.substring(position);
	System.out.println(value);
}

Next, you need to convert your data into rows. This can be done using a tJavaFlex. I will assume that you can get the data into a globalMap variable. If not, look at the tSetGlobalVar or tFlowToIterate components. Once your data is in a globalMap variable, you can use the following code with your tJavaFlex....

 

Start Code

String data = ((String)globalMap.get("mydata"));
while(data.indexOf('.')>-1){

Main Code

int position = data.indexOf('.')+2;
row1.value = data.substring(0,position);
data = data.substring(position);

End Code

}

This will output your data in separate rows.

2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog