SPLIT STRING WHERE lowercase begins and only keep uppercase letters

There are a few members to memorize, .Match().Value, .Split(), and .Replace()
In my example, I chose to use .Split(), so it will take everything before the first lowercase character. They all can be used depending on what you are trying to do.

My question is what does the variable “MessageArray” represent? Is it an array of paragraphs that contain many messages, or is it an array of message lines (like if your initial post there are 3 message lines).

The reason I ask is that if you have an array of those message lines, then you will need to use a query method or run them through a ForEach.

If you can clarify that, then I can suggest how you can extract all the message lines from a single paragraph.

Regards.

Okay… So when I extract the information from the app I’m using it will only let me extract the whole row from the data table. So I have the customers information and I have the status of the activity I’m automating. When I split the information to get just the status part, it’s normally stored in MessageArray(1). For some odd reason, when the Status contains one of these really strange errors that just keep going on and on and repeat themselves my Array is only size 1, so I only have MessageArray(0) and that’s the whole message. It doesn’t contain any of the customer data. So When one of these really long Messages are returned I need to get rid of all of that nonsense and it needs to only return the important part of the status so that your average joe is like, “OH, It’s disconnected at the switch” Then they can investigate into that.

So right now I have an if statement,

if(MessageArray.Length = 2){
StatusMessage = MessageArray(1)
}
Else
{
StatusMessage = regex.Match(MessageArray(0)).Value
StatusMessage = Left(regex.Split(StatusMessage, "[a-z],…) (Is this how you are using this?)
}

StatusMessage = regex.Match(MessageArray(0)).Value
This didn’t return anything.

And This one Threw an error:
Left(regex.Split(StatusMessage, “[a-z]”)(0), regex.Split(StatusMessage, “[a-z]”)(0).Length-1)
Assign : Argument ‘Length’ must be greater or equal to zero.

Probably because the first one was empty. I guess.

I see. So if MessageArray(0) only contains 1 line then it should work.

Btw, you can also use .Last if the message is always the last item in the array.
MessageArray.Last
This will return the (1) or the (0) if it’s the last index. Although, this won’t work if it’s not the last index every time. But, just thought I’d point this out so you don’t need to use an If condition.

Yes, I’m using this but StatusMessage is the entire message line, so I’m not doing any extra regex match. (ie "SUCCESS COMPLETED SUCCESS")

So, you could probably remove the Regex.Match right before it, unless there’s a reason for it.

Regards.

That’s a good idea. I don’t know if that will work for all cases, because there are potentially more cases that I can’t replicate on demand, but I will try that.

Also, use my fix shown in the EDIT above post. So it will work if there are no lowercase letters found.

And yes, your first line returned empty string probably.
I would say just replace StatusMessage in the code to your Message item

If(rgx.Split(MessageArray(0)).Count>1, Left(rgx.Split(MessageArray(0))(0), rgx.Split(MessageArray(0))(0).Length-1), MessageArray(0))

There it is again.

Regards.

EDIT:
sorry moving too fast. the variable rgx is a Regex using the pattern “[a-z]” for all lowercase letters.
Note, you can change the code to use the pattern in the code too. See previous posts or let me know if you didn’t understand.

I gotta leave for the day. I’ll try to get back to either tomorrow (maaaybe) or Wednesday if I can, if you still have some questions.

Here is a clarification of how I set it up using an Assign activity to store the status to a variable:

If(System.Text.RegularExpressions.Regex.Split(message, "[a-z]").Count>1, Left(System.Text.RegularExpressions.Regex.Split(message, "[a-z]")(0), System.Text.RegularExpressions.Regex.Split(message, "[a-z]")(0).Length-1), message)

where message is a variable that represents the message line (ie MessageArray(0))
This Splits the message by the first lowercase letter, then strips off the last character.

If the message variable used is not the message line you want to extract from then you will need to work on getting the message to how you have it in your examples. Let me know if you need help with this also, but like I said I’ll have to get back to you at a later day.

Here was the output using your first example message:
image

regex.Split() is splitting the text to an array if it finds a regex match, then (0) is taking the first item.
regex.Split(StatusMessage, “[a-z]”)(0).Length represents the number of characters from the item that was extracted, and the -1 is telling it to use minus 1 character. This way Left() method can take all characters up to the last character “minus 1”. The reason for the minus 1 is because a lowercase character will either have 1 uppercase character or 1 space character before it - but if this is not the case, then let me know :smiley:

Hopefully that was clear for you. If it still is not, let me know and I will try to clear it up when I get a chance.

Regards.

3 Likes

Okay, I’m soon to go home too. I’ll talk to you next year.

My Mistake, I fixed something, and now it’s all working. Fabulous! Regular Expressions Make me Regularly Express Frustration! Hopefully it’ll be easier one day.

1 Like

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