IndexOf on string not working as expected

I’m trying to get the companny name from a outlook message.
I first retrieve all the messages, then loop the list and use item.Body.Substring(item.Body.IndexOf(“From”) to cut a part of the body of and make shure I’m getting the correct emailadress, then I tried to use .Substring(.IndexOf("@")+1, .IndexOf(".")) to get the domainpart of the emailaddress, but getting more then I ask for :slight_smile:
For example for the emailaddress d.farnir@abm-tecna.be, I’m getting abm-tecna.be> Sent: F
while I’m trying to get abm-tecna.
Anyone knows how to achieve this and more important why my end of the substring dosnt work?

BTW before someone asks why I don’t try to acces the from directly by using item.From.Address I refer to my other post, where I explain that I tried it, but it didn’t work, so this a workaround untill someone provides me with a possible answer on the different post, but I will still need it to select the domainpart in the from

If I’m not mistaken the second parameter of the substring is not another index, it the amount of characters to retrieve after the first index you defined.

So you’ll probably need to infer how many characters you want. This could be achieved substracting the first index to the latter index, thus getting the amount of chars between them, aka the string you want. You could try with something like:
Substring(.IndexOf("@")+1, .IndexOf(".") - .IndexOf(“@“))
I may be missing a “-1”, I’m not with my PC so I can’t confirm it right now.

Ah ok, yeah I’m a java developer and in java the second index is the end index, I try what you suggested and mark your answer as the solution if it works… Thanks

1 Like

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