How to split and read first character of string

Hi,

I have a task to query a telephone number from my database. The result of the database query is varied. Here are some example :

+621234561412, 01251265236, 62124162316326, +6251325235213
62123445432, 01256236432
01232115156, +62163434636
8913214214

The goal is :

  1. I have to output the first 3 phone number in 3 different column in excel format. So if there are 5 phone number, I just have to take first 3. The phone number separator in my database is using comma (,)

  2. The phone number output must be 62, not +62 or 0 or without 62. Every phone number MUST have 62 in the front of it.

I tried to use StartsWith and Remove but somehow it’s not working. Any idea for this case? Thanks :slight_smile:

Hi @Rhys18 ,

Could you let us know if the data is contained in a Datatable format or String format ? Or is it already present in the array format?

Also Could you show us How you have performed this implementation ?

The data is presented in string format. I queried then I use for each row activity and I got in in string.

So if I write the data table, it will write to the excel like the example I give to you. It’s not in Array format, just simple write datatable

image

Sure, this is how I do it

Note : No_hp = phone number

image

image

@Rhys18 ,

Considering the conditions mentioned, from the String data provided, How would you Output it to excel and which would be the 3 values that you would choose if done manually ?

Ok, I assume you still confuse about the output. Here’s the expected output :

image

1 Like

@Rhys18 ,

Could you check with the below Expression :

Let str be the string variable which contains the data, then we can perform a split based on comma and convert it to an array of String. We can then perform a modification on the values as per the conditions and then select the modified values as the new set of values.

str = "+621234561412, 01251265236, 62124162316326, +6251325235213, 8913214214"

First3Values = Split(str,",").Select(Function(x)if(x.Trim.Trim("+".ToCharArray).StartsWith("62"),x.Trim.Trim("+".ToCharArray),"62"+x.Trim.Trim("+".ToCharArray).TrimStart("0".ToCharArray))).Take(3).ToArray

Here First3Values is a variable of type Array of String.

You should be able to use this array value as the input to the Add Data Row Activity

Immediate Panel View :
image

This is the output :

@Rhys18 , Could you show me your Add Data Row Activity Properties or the value that is being passed ?

Did I do it wrong?

image

@Rhys18 ,

Try Specifying just no_hp do not add the brackets

Ok it’s working as expected! Thank you Mr. Arpan :smiley:

1 Like

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