Get the last two words on a sentence

i want to get the last two words in a sentence for example “this is a test result.” and i want to get in the output is “test result”. how can i achieve this? i’ve been trying for days but i can’t seem to find any solution as the sentence changes it’s length dynamically. is there any way to achieve this goal? i’m a newbie so i still don’t know a lot.

Hi @Tammy1998

Try this,

myString = "this is a test result."
outString = myString.Split(" “c)(myString.Split(” “c).Count-2)+” “+myString.Split(” “c)(myString.Split(” "c).Count-1)

Best Regards,
JothyPrasanth M

1 Like

this works but it’s throwing me an error after the turn…

how can i solve this?

Hi @Tammy1998

Can you send what you using in the two assign activity

Best Regards,
JothyPrasanth M

1 Like


hi. i’m doing it inside a for each row. i have to find the address and put remarks if it in the category of first array of strings, or in the second one or in the third one.

City = row(“AREA”).ToString.Trim.Split(" “c)(row(“AREA”).ToString.Trim.Split(” “c).Count-2)+” “+row(“AREA”).ToString.Trim.Split(” “c)(row(“AREA”).ToString.Trim.Split(” "c).Count-1)

Try this

Best Regards,
Jothy Prasanth M

1 Like

still having this error…

Make sure that you have the value in row(“AREA”).ToString
If possible can you share the workflow so that i can look into it.

Best Regards,
JothyPrasanth M

1 Like

config area breaking.xaml (23.5 KB) TEST CITY.xlsx (40.0 KB)
this is the workflow and example excel file

Hi @Tammy1998

The error is from the below data

I am splitting the word by space and expecting more then one word in a sentence but in the lase two data only one word is there in a sentence that’y why it’s throwing the error.

remove the last two row and try to run

Best Regards,
JothyPrasanth M

1 Like

yeah it works but why does my for each row run only once? it stopped reading after reading the first row.
why is that?

i am checking if value city is inside the array values and write which array value are they in. but now my for each loop only read the first row and won’t read the following rows. could there be a problem in my condition?

@Tammy1998 Based on the Question, You want to get the Last Two words in a Sentence, but what if there is only a Single word in the Sentence, In that Case what should be your Output?

i will put a write cell activity saying N/A or no action will be made and skip

@Tammy1998 I have made a bit Change in your Workflow, Check if it’s working as you wanted it to.
config area breaking.xaml (24.9 KB)

hi thanks for the tip… it works but it only read the first row and it will stop running. i wonder what could be the problem…

@Tammy1998 What Should be the output according to you?

1 Like

hi. the output was correct. but i want to check for each row of the data whether the row is found in ncr or luzon or vizmin. the problem is it doesn’t check the for each row…

@Tammy1998 Actually the For Each Row is Looping through Each of the rows, But the Condition matches only for One row.I did a Little Debugging to find that out. But Since it Contains many records I didn’t try out with all the Records, Please Debug for Each records and check.
config area breaking.xaml (24.7 KB)

1 Like