Maximum Length doubt

Hello, Can you please let me know when I am using the command Split(“someone@example@com”, “@”,3)–> its spliting the string into 3 strings
whereas when Split(“someone@example@com”, “@”,0) → it should give me the output as "someone@example@com but it is showing indexOutofRangeException why?

Please read this.
Split(expression[,delimiter[,count[,compare]]])

Parameter Description
expression Required. A string expression that contains substrings and delimiters
delimiter Optional. A string character used to identify substring limits. Default is the space character
count Optional. The number of substrings to be returned. -1 indicates that all substrings are returned
compare Optional. Specifies the string comparison to use.

Can have one of the following values:

  • 0 = vbBinaryCompare - Perform a binary comparison
  • 1 = vbTextCompare - Perform a textual comparison|

Hello thats right -1 as the limit/count returns me the all the available sibstrings separated by the delimiter, but in the case of 0 as the limit/count it should return null or the complete string? I am sorry can you please explain this a bit

1 Like

0 and 1 are compare options which are 4th options in the Split function.
you can use 0 number or “vbBinaryCompare” word in quotes.
you can use 1 number or “vbTextCompare” word in quotes as 4th option.
You have used only 3 options in your Split function and referring for 4th option.
I request you to please read full article about Split function. it will give full insight.

Hello I guess you got me wrong I am not referring to the compare functionality in the split function I am referring to the count functionality. I am passing 3 parameters in my split function (String,delimiter,Count) no compare has been used now, If I take count value as 1 it will return me a string substring that is the string itself no spiliting will happen but when I give count value as 0 it should give me an empty String array or null or the complete string in the output. I hope now you will get me when I doubt is?

This usually starts from 1 buddy
That’s why
—Even in the previous one as we have mention 3 it gave us three SubStrings out of the string
And so we need to mention from 1
As it is a Count and not a index

That’s the reason why you were getting that error
Hope this would help you
Cheers @Avijit_Pal

2 Likes

Hello Palaniyappan I got you ,but it should have given me an empty string right like for the example if I take Split(“XX”,“X”) in this case we are 2 delimiters one after the other but it gives us a an empty string[*] because the split function is considering this as a empty string.

1 Like

yes ofcourse it would give us empty string obviously because we dont have any value aside to the delimiter i.e., on either sides of the delimiter
for example

but if i have any character aside to the delimiter only then we would get the value
here (2) next to split method is a index and usually index starts from 0 position but the count usually starts from 1 as said earlier

hope this would help you
Cheers @Avijit_Pal

1 Like

Thanks a lot @Palaniyappan and @rkelchuri :slight_smile: :slight_smile:

1 Like

cheers @Avijit_Pal

1 Like

Hey @Palaniyappan a question that popped up if you use a for loop
like for item in Split(“@@”, “@”) it will print out 3 empty string but seems like when you used writeline activity where you used the method .ToString it concatenated all the empty string as 1 and the value 23 as another Is it so?

1 Like

no buddy i didnt concatenate
if the input is
str_input = “@@23
then the output with the split method having delimiter will be in writeline like this
now string has @@23 so three places with @ as delimiter
|@|@|23 like this
0@1@2 - index position

–to get the value of second index position that is 23 from the string i used
Split(str_input,“@”)(2).tostring

cheers @Avijit_Pal

1 Like

Great thanks a lot @Palaniyappan, now its clear…

1 Like

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