Replace first number

I have an Excel table. In one of the columns, the text is, for example, ‘0000000011111111’. How can I replace the first ‘0’ with ‘4’, so that it becomes ‘4000000011111111’?

Hi @plamenov.plamen

  1. Excel Application Scope
  2. Read Range
    SheetName: Name of the sheet containing the data
    Range: Range of the data to read
    Output: dtTable (DataTable)
  3. For Each Row
    Input: dtTable
  4. Assign
    To: row(“YourColumn”)
    Value: System.Text.RegularExpressions.Regex.Replace(row(“YourColumn”).ToString(), “^0”, “4”)
  5. Write Range
    SheetName: Name of the sheet to write the data
    Range: Range where you want to write the modified data
    Input: dtTable

Hope it helps!!

Hi @plamenov.plamen

Try this:
Use a “For Each Row” activity to iterate through each row of the DataTable.
In Assigin: row(“ColumnName”) = row(“ColumnName”).ToString().Replace(“0”, “4”,1)

It will replace the first “0” value.

Hope it helps.


Assign: row(“ColumnName”) = row(“ColumnName”).ToString().Replace(“0”, “4”, 1)


Read Sheet and shore in DT
Put for Each over DT
inside for loop put if, If is to check number first letter is zero or not and put condition->

If row("ColumnName").ToString().StartsWith("0") Then

put Assign activity inside then block and put like this->

row("ColumnName") = "4" & row("ColumnName").ToString().Substring(1)

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