Describe this expression

Hi everyone,
I saw the acme video on youtube where they are using this expression
gettext.Substring(gettext.IndexOf("Client ID: ")+"Client ID: ".Length).Split(Environment.NewLine.ToCharArray)(0)

please tell me the meaning of this expression
where gettext is a variable

1 Like

Hey @Lakshya_Garg

Here is the explanation…

gettext.Substring(gettext.IndexOf("Client ID: ")+"Client ID: ".Length).Split(Environment.NewLine.ToCharArray)(0)
  1. gettext.IndexOf("Client ID: ")+"Client ID: ".Length Getting the position of the last letter of the Client ID: text from the string content gettext

  2. gettext.Substring(gettext.IndexOf("Client ID: ")+"Client ID: ".Length) Removing the Client ID: label from the string content

  3. .Split(Environment.NewLine.ToCharArray)(0) Splitting the content into an array where each element is a line in the string content and fetching only the first array element which has the actual Client ID value

Hope this helps

Thanks
#nK

1 Like

Nice explanation @Nithinkrishna

1 Like

Well explained :+1: @Nithinkrishna

1 Like

Hi @Lakshya_Garg ,

Let’s break this Expression into individual pieces and Explain

Let’s take an Example String as well :

gettext= "Client ID : 1111212 
          Client Name : Jack"
  1. gettext.Substring(gettext.IndexOf("Client ID: ")+"Client ID: ".Length)

The Above Expression is using a String Substring Method.

The Syntax goes as below :

String.Substring(startIndex, length)

startIndex - An Integer value indicating the position from where the start of the String should be selected. (Should not be greater than the Length of the String-1)

From your Expression, You are retrieving the Start Index of the Client ID: String and you are adding the Total Length of the Client ID: String to it.

We can use the Debug Panel to Check the Expression Individually :

Combining the Two in the Substring Method would provide us the below result :
image

  1. Next Expression, Split(Environment.NewLine.ToCharArray)(0) , the Split Method Applied on the Substring Resultant value.

Split - As it is named, Splits the String based on a delimiter.

Syntax is as below :

String.Split(delimiter) :

Let’s take it directly to the Debug Panel :

What we would need is the Client ID value from the String, In the String as observed we have a New Line followed by the Client Name values. To Separate the Client Name from the Client ID value, we use the Split method with New Line as the Delimiter resulting in the below as shown :

As Explained by @Nithinkrishna , Split(Environment.NewLine.ToCharArray) would split the value into multiple lines. The Split(Environment.NewLine.ToCharArray)(0) would take the First Split Value

image

Let us know if you Still need more explanation on the above.

7 Likes

Great explanation @supermanPunch it is giving more clarity with the examples. Nice to see your post.

2 Likes

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