Data to a specific CSV column

Hello guys,
I have something basic to do, but I can’t find how…
I read a .txt file with a list of login ID’s and store the data into a string variable :
toto
titi
tutu
And I need to write this data into the specific Login column of a .csv file:
Name,Login,Mail
The other columns are already populated.
How can I achieve that ?

HI @remy2283

use like this str.Split(Environment.Newline.ToCharArray) and use loop to loop through the output array

cheers

@remy2283

Please see below

Input

Output
image

What to do(filling the data into column2)

str contains the string read from file
dt is the datatable read from CSV

abc.xaml (9.9 KB)
cheers

Hello Anil G, thanks for your quick response.
But your xaml file seems corrupted, I can’t open it.

Hi @remy2283

Can you implement it using the attached screenshot

I am looping through the datatable read from the csv file and then updating the required column

Index is from the for loop properties

str is the string which you read from the text file

You are not able to open may be because of version difference let me know your version if you are not able to recreate xaml using the information

cheers

My version is Studio 2021.10.4

Hi @remy2283

Try these two

windows.xaml (9.3 KB)
Legacy.xaml (9.2 KB)

cheers

It is better, thanks.
But it is not working, if I execute your script and write a csv, it gives me the same value for the column 2 :
Column1,Column2
text,Titu
yext2,Titu
Text3,Titu

@remy2283

Please include index in the for loop properties as well

like this

I missed while converting

cheers

This is working.
Geez, you are good.
Many thanks :slight_smile:

1 Like

@remy2283

Happy automation.

Can you please close it with solution so that others with similar query can also find it

Cheers

Hello Anil, I come at you.
I adapted your example to my script, but it is working halfway.
My .csv is updated with one line out of two…

Column1,Column2
text,Tito
yext2,
Text3,Titu
Text4,

@remy2283

Send the xaml or show the screenshot what you did

Cheers

How do I put the text in separate columns in the CSV file in…
Select the first column (column A)
Click on ‘Data’ and then on ‘Text to Columns’
The option ‘Delimited’ has been preselected. This is the correct option. Click on ‘Next’.
Select the option ‘Comma’ and click on ‘Finish’

Regards,
Will

Main.xaml (11.1 KB)
Hello Anil, here is the file…

Hi @remy2283

Please check the text input you provided is it having a empty line between two names I believe that is the reason you are having a blank item in between

please check the string in notepad is like this

image

cheers

Hello Anil,
No, there is no empty lines in my txt file.
But I managed to remove the issue with the command
LoginID.toString.Split({Environment.NewLine.ToCharArray},StringSplitOptions.None)(index)
It is working now. Thanks for your tremendous help !

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.