How to add multiple data in a particular location in a text file

Hi,
I have a notepad with the following data
Name1:
Name2:
Name3:

I have the respective names in a data table

I want the notepad to be as follows

Name1: abc
Name2: xyz
Name3: lmn

can you please tell me how to go about it? I tried using the String.Format() function inside a loop, but I am getting the following output

Name1: abc
Name2: abc
Name3: abc

Name1: xyz
Name2: xyz
Name3: xyz

Name1: lmn
Name2: lmn
Name3: lmn

Please help!
Any suggestion is welcome!
Thank you

Hi,

Can you please share your xaml file.

thanks
Debakanta

Hi,
I dont have the xml file as I was just trying it out, but I hope you understood my problem statement.

I have a text file with
Name1
Name2
Name3

I need an output as
Name1: abc
Name2: xyz
Name3: lmn

I used the above method.

I created a for loop and inside the loop i have the String.Format(in_text, Name)

and that is not giving me the required output

HI @ice_cream,

can you please try this.
Prepare text file like.
Name1:{0}
Name2:{1}
Name3:{2}

use String.Format(strTextFile, name1,name2,name3)
where strTextFile is textfile text, and name1, name2&name3 are variables for names.

thank you,
Debakanta

Hi @Debakanta_Mahanta

Yes that works if i know the number of variables to be passed, but i do not want to hard code, so it is possible to do it when we dont know how many names are there?

Hi @ice_cream

on that case one more way to implement :
strTextFile.Replace(“Name1:”,“Name1:”+name1).ToString
strTextFile.Replace(“Name2:”,“Name2:”+name2).ToString
strTextFile.Replace(“Name3:”,“Name3:”+name3).ToString

Thanks,
Debakanta

1 Like

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