Using LastIndexof method

Hi,

I am running into issues trying to extract a value within a cell in Excel.

  1. I have 2 columns “OrderNumber” and “InvoiceNumber” in my datatable.
  2. if ordernumber doesn’t have any value,I need to extract it from my “InvoiceNumber” column
  3. the Invoice number is a concatenated value separated by hyphens as shown below. i need to extract the value after the last hyphen
  4. I am trying to use lastIndexof method but havent been successful so far.

Any help is greatly appreciated.


@parimala.prata
Welcome to Forum.

give a try on: row(InvoiceNumber).toString.Split("-"c).Last().Trim

Thank you.
I tried both of these below and the output doesnt seem to change.

  1. row(InvoiceNumber).toString.Split("-"c).Last().Trim
  2. row(“InvoiceNumber”).ToString.Substring (row(“InvoiceNumber”).ToString.LastIndexOf(“-“)+1)

can you post a sample value as text here? Thanks

Values in the InvoiceNumber column could be in any of the format below.

  1. COLL-103227712-0311969189
  2. 103143446-0311442428
  3. 103004206

@parimala.prata
grafik

I would suggest that you debug and inspect the row / Col Values

strange because the workflow was just working as designed until i tried to attempt this. Thank you for your input.

@parimala.prata
Also in the IF condition do the check on empty rows like this:
String.IsEmptyOrWhitespace(row(“OrderNumber”).toString.Trim)

1 Like

its the if condition syntax that is wrong. This worked. Thank you. Appreciate your quick help.

(String.IsNullOrWhiteSpace(row(“OrderNumber”).ToString.Trim)) and (row(“InvoiceNumber”).ToString.contains("-"))

Thank you,
pari

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