Logic to write the text in particular place

I have a text file like this

Name: swetha
Age:
Area: India

My input is 20 and I want to put it next to Age:

Please help with logic

1 Like

Fine save this text in a text file that is .txt file
Name: swetha
Age: {0}
Area: India

Where 0 is the place holders that will pass the value we want
So in studio
—use a read text file activity and pass the file path above text file and get the output with a variable of type string and name it as in_text
—using writeline and mention like this
String.Format(in_text,”20”)
This 20 will get placed in the place holder {0}

1 Like

Wow… Thank you @Palaniyappan

1 Like

If the input word file should not be changed

I didn’t Get that please come again

Hi @Sweety_Girl - Try this

Create a String Array variable and assign this code - “Your Variable” is the output variable of Read Text File YourStringArrayVariable = “YourVariable.Split({Environment.NewLine},StringSplitOptions.None)”

The above code will split the string and you want to insert the text between first and second line

Then assign the Your Variable = “YourVariable.Insert(YourStringArrayVariable(1).Count,” 20")"

Then Write Text File using “Your Variable”

Thanks,
AK

I have a text file like this

Name: swetha
Age:
Area: India

My input is 20 and I want to put it next to Age:

Please help with logic

Here where the input we have to add {0} to make the text to come in that place

But I cannot add that {0} in that particular place

We can put this string
Name: swetha
Age:
Area: India

In text file
Weren’t we able to mention them in a .txt file
Cheers @Sweety_Girl

Have a text file and have to feed these input in that text file

Yes of course
I m sorry if I didn’t get the question yet
Kindly Correct me if I’m wrong
Cheers @Sweety_Girl

Have a text file

Where the text is

Name: swetha
Age:
Area: India

I have to insert the age as 20… where I cannot change my input file in the string format like{0}

Without that I have to make it

1 Like

How to make it work in the array variable 4th index @AnandKumar26

1 Like

Is there any other method to achieve that… that is without using the string.format, bcz I cannot change my input to format type @Palaniyappan

1 Like

yes of course
to do that
–use read text file and get the output with the string variable named out_text
–use a assign activity like this
out_text = out_text.ToString.Replace(“Age:”,“Age: {0}”)
–now use a write line like this
String.Format(out_text,“20”).ToString

Cheers @Sweety_Girl

Change the value from 1 to any value of array index as shown following Your Variable = “YourVariable.Insert(YourStringArrayVariable(3).Count,” 20")

Thanks,
AK

1 Like

thats a good point @AnandKumar26
but we need small changes like
–use a read text file and pass the file path of the text file and get the output as a string variable named in_string
–use a write line activity like this
in_text.Insert((in_string.IndexOf(“Age:”)+5),“20”).ToString

Cheers @Sweety_Girl

Thank you so much @Palaniyappan

1 Like

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