Get substring in Text file

Hi all,

I have a text file where I have data with | seperator
Date|ID|Amount|NA|NA

From this i want to remove |NA|NA.

And write the same into the text

How to go with this

Hello @hanviprebday

  1. Read Text File activity:
    FileContent = Read Text File “path\to\your\file.txt”

  2. Assign activity:
    ModifiedContent = String.Join(Environment.NewLine, FileContent.Split(Environment.NewLine).Select(Function(line) line.Replace("|NA|NA", "")))

  3. Write Text File activity:
    Write Text File “path\to\your\file.txt” (content: ModifiedContent)

Thanks & Cheers!!!

Hi @hanviprebday ,

You can follow the below sequence:
Read Text file
replace string “|NA|” with nothing
Write back the content to the text file

Hi @hanviprebday

Try this:

Read Text File
   Input: YourFilePath (path to your text file)
   Output: YourTextVariable (string containing the file content)

Assign
   YourTextVariable = YourTextVariable.Replace("|NA|NA", "")

Write Text File
   Input: YourFilePath (path to your text file)
   Input: YourTextVariable (the modified string)

Hope it helps!!

@hanviprebday

Read Text File:

Use the “Read Text File” activity to read the contents of your text file.
Set the file path in the activity properties.
String Manipulation:

Use the Assign activity or the “Assign” block inside a sequence.
Assign the output of the “Read Text File” activity to a variable (let’s call it fileContent).
Use the following expression to replace “|NA|NA” with an empty string:

code
fileContent = fileContent.Replace(“|NA|NA”, “”)
Write Text File:

Use the “Write Text File” activity to write the modified content back to the text file.
Set the file path in the activity properties.
Set the Text property to the variable containing the modified content (fileContent).

@hanviprebday

you can also try with this

inputstr is the output of read text file

string.join("|",inputstr.split("|").ToArray.where(Function(a) not a.ToString.Equals("NA")).toarray)

after that use write text file activity to write back to text file

@hanviprebday

Read the text file
OutText.replace(“|NA”,")

image

Cheers!!

Hi @hanviprebday ,
You can use read text file to get String strText
then remove “|NA|NA”
strText = strText.Replace(“|NA|NA”,“”)
then write to text file
regards,

Thank you friends I got it

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