Remove odd indexed characters from a given string

Input: str = “abcdef”
Output: ace
Explanation:
The characters ‘b’, ‘d’ and ‘f’ are present at odd indices, i.e. 1, 3 and 5 respectively. Therefore, they are removed from the string.

Input: str = “geeks”
Output: ges

by using UiPath how we do that

One way would be to use substring:

str_input = "abcdef"

str_output = str_input.Substring(0, 1) + str_input.Substring(2, 1) + str_input.Substring(4, 1)

Here is a very good post:

Hi @Sohil_bagwan1

  1. Use an Assign activity and give the input say inputString.
inputString = "abcdef"
  1. Use another Assign activity for output say resultString.
resultString = ""
  1. Use for Each activity and give the below condition:
inputString.ToCharArray()
  1. Use If activity inside for each activity and give the below condition:
inputString.IndexOf(currentChar) Mod 2 = 0
  1. in then sequence of If activity use assign activity save the result to resultString initialized before.
resultString = resultString + currentChar.ToString
  1. Print the value of resultString in writeline or message Box.

Note: Attached the workflow for better understanding and reference.
Main.xaml (8.7 KB)

Hope it helps!!
Regards,

Hi,

Can you try the following expression?

String.Join("",yourString.Where(Function(c,i) i mod 2=0))

image

Regards,

1 Like

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