i have excel file here i want the first 3 digits
2XL40
YTB28
XMA124
YTB80
XMA52
XMA67
XMA148
XMA100
XMA89
XMA140
XMA21
Please see “Substring”
HI,
Can you share expected result?
Regards,
2XL
YTB
XMA
YTB
XMA
XMA
XMA
XMA
XMA
XMA
XMA
Hi @T_Y_Raju
Try this
dt.AsEnumerable.ToList.ForEach(Sub(r)
r("Data")=r("Data").ToString.SubString(0,3)
End Sub
)
Input:

Output:

Cheers!!
Assign activity:
dtResult = dtOrigData.Clone
Assign Activity:
dtResult =
(From d in dtOrigData.AsEnumerable
Let vs = d(0).ToString.Trim.Substring(0,3)
Let ra = new Object(){vs}
Select r = dtResult.Rows.Add(ra)).CopyToDataTable
Also keep in mind that it can be done with essential activities directly e.g. within a for each row activity and changing the col value within an assign activity
To extract the first three digits from each string in your Excel file using UiPath, you can follow these steps:
- Read Excel File: Use the “Excel Application Scope” activity to read the Excel file.
- Read Range: Inside the Excel Scope, use the “Read Range” activity to read the data from the Excel file into a DataTable.
- Loop Through DataTable: Use a “For Each Row” activity to iterate through each row in the DataTable.
- Extract First Three Digits: Inside the loop, use the
Substringmethod to extract the first three characters from each cell value. - Output or Store Results: You can output the extracted digits to the console, write them to another Excel file, or store them in a variable, depending on your requirements.
- Excel Application Scope (Provide the path to your Excel file)
- Read Range (Output: DataTable, say dtData)
- For Each Row (ForEachRow activity, Input: dtData)
- Assign activity:
- Variable: cellValue
- Value: row(“ColumnName”).ToString().Substring(0, 3) - Write Line (or any other activity to output/store the extracted digits)
- Text: cellValue
foreach (string line in lines)
{
// Extract the first 3 characters (or less if the line is shorter)
string first3Digits = line.Substring(0, Math.Min(line.Length, 3));
Console.WriteLine(first3Digits);
}

