How to keep only the first character in an excel table?

For each excel row, I wish to retain only the first character of Column B and delete the rest of the text in the excel cell. For example Andy: to keep only ‘7’ in column B.

Hi @Snow , welcome to the community.
I am attaching a workflow for your reference which might help you to get your solution. Also, sending the sample excel file.
Grade.zip (7.3 KB)

Have a nice day!

Thanks & Regards,
Shubham Dutta

Hey @Snow,

Follow the below steps:-

  1. ForEachRow activity
    2.Assign activity
    Left = item(“Grade”)
    Right = item(“Grade”).ToString.Split(";"c)(0).Trim.ToString

Thanks,
Sanjit

Hey!

Try this:

  1. Read range - Output as - DtOut
  2. Take one for each row in data table pass the DtOut
  3. Take one assign activity and create one integer variable as Counter initialize with 1
Assign Counter = 1
  1. Take one assign activity and pass the expression like this
Assign First = System.Text.RegularExpressions.Regex.Match(CurrentRow(1).ToString.Trim,"\d{1}").ToString
  1. Now use write cell activity to write back the values to excel
Range : "C"+(Counter+2).ToString
Value : First
  1. Assign Counter = Counter+1

Try this and let me know

Regards,
NaNi

Hi @Snow

Regex expression

OutData = System.Text.RegularExpressions.Regex.Match(CurrentRow("Grade").ToString,"^\d+(?=;)").ToString

Check out the XAML file

KeepOnlyFirstCharInExcel.xaml (11.7 KB)

Output

KeepOnlyFirstCharInExcel.xlsx (7.2 KB)

image

Regards
Gokul

Hi @Snow , welcome to the community!

In your for each row, you can assign item(1) = item(1).tostring.split(";"C)(0).tostring.trim
Then, you can see
Andy 7
Belle 6
Clark 9

Try This

Xaml is attached
DT_Update.xaml (5.7 KB)

Thanks,
Muthuraj

2 Likes

Thanks for your help!

1 Like

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