Split

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.

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 GARNER 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

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.

Download