susi
August 7, 2021, 7:25am
1
Hello,
I have a question about "split"
Could you help me?
(Sorry for my English)
I made an example
It shows
"Select list item: Attempt to get item number 2 of a list of length 1: (12345)"
I know it's because it can't find "6"
I want it tells me it can't find "6"
But the "ErrorOccurred" doesn't work
So I use an "IF" block
It works
But it's too complicated
There are too many
Is there a better way?
Thank you
Your code must be clean and protected against incorrect situations. If you can serve IF blocks, as you did it below. You can also use extensions:
Try&Catch Hi everyone, I hope you are all good. Today I come with a little extension but very useful for you. This extension allows you to call methods and set the properties with try and catch. What is Try & Catch? Try and catch place around...
Reading time: 1 mins 🕑
Likes: 22 ❤
susi
August 7, 2021, 12:14pm
4
How to use it?
It shows
"The arguments , [(12345)], [2] are the wrong number of arguments for SelectListItem"
What is the "ID" for?
If I split the text twice, will the extension tell me which produced the error?
How to use the extension can tell @iamwsumit
I think the identifier is used to let you use the method in many places in the app. When an error occurs, the event will return an ID and you will thus know which block the error occurred in. The ID must be different for each instance of the method in the blocks. It can be any number, e.g. 0,1,2,3,4, maybe, it can also be a string, e.g. "list1"
1 Like
Yes. You're right.
I think @susi confused about it because the id param is not in the usage blocks because it was added afterwards.
No. It's not necessary. You can use the same id again but carefully as it may confuse you.
Patryk_F:
it can also be a string
You can pass string to it.
Taifun
August 7, 2021, 1:52pm
7
Then you should use the contains block, which returns true or false...
Taifun
susi
August 7, 2021, 2:14pm
9
Thank you, Sumit1334
When I split text at "3"
It shows
"45"
But when I split text at "6"
It shows
"call to 'TryCatch1$Catch' has too few arguments (1; must be 2)"
Did i miss something?
How can you split a string at 6 which does not have 6 in it?
That just won't cause an error. A single-element list "12345" will be returned, which is not split.
susi
August 7, 2021, 2:21pm
12
So I want it tells me there is no "6"
In real application, I split the string many times, when an error occurred, I don't know which is not exist
That's why selecting 2nd item throws error.
Check list length.
If greater than 1 then it means that particular item exists else not.
He did it as shown in the first post, but he doesn't like this solution, he wants a different one.
But I also think that the method will be the best there. You can also select it, make a procedure that will check the lists. Then it can be used in many places.
Besides, maybe it can be solved in a completely different way, we would have to know the author's intention.
Taifun
August 7, 2021, 3:11pm
15
What about following my previous advice then?
Then you should use the contains block, which returns true or false...
Taifun
Taifun
susi
August 7, 2021, 3:12pm
16
I am ...
OK I rewrote it!
Is it better?
I have a lot to rewrite
susi
August 7, 2021, 3:16pm
17
You mean here?
Or there is another way...?
Write what do you need? Do you want to search for text in a list or in a string?
susi
August 7, 2021, 3:42pm
19
string=123456789
need after "2"
→string=3456789
need after "5"
→string=6789
need before "8"
→string=67→what I need
Today one of "2","5","8" is changed (or all of them changed)
I need to know which, or I have to check many times