How to extract value from Data pattern

Hello Experts,

How can I extract numbers from the following strings:

"P:200:4401:25:000565 | Sanar Co | 1045 | IMR"   -- Extract 1045
"P/200/6401/35:000665 | Sanar Co | 1046 | IMR" -- Extract 1046
"P-500-6401-45-555665 | Sanar Co | 1049 | IMR" -- Extract 1049

Thanks.
JimiJ13I T ConsultantAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

d_yorkCommented:
if the data is well formatted, use String.Split().  You could stick it in a foreach loop, but here I'll split one of your strings so you can see:
            string _test = "P:200:4401:25:000565 | Sanar Co | 1045 | IMR";
            string[] _split = _test.Split('|');
            int _number = Convert.ToInt32(_split[2]);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JimiJ13I T ConsultantAuthor Commented:
d_york,

Thanks. Actually, that's already my existing solution but, that doesn't work with "/", "-", & ":" present in the string.


Any idea?
0
d_yorkCommented:
works in English in C# .Net for all those strings - those are not metacharacters.  I hate to say "normal" but this should work on a "normal" setup without issue.  Something else is going on, you've got more going on than a simple set of pipe delimited lines of text.  You'll probably have to divulge more information to get assistance from those more worldly than me.  But if I were just handed this issue to debug in code I'd be looking at:
1) Encoding:  If I'm reading delimited text from file am I really getting what I think I'm getting?  I'd be looking at the language and the encoding being detected.
2)  Operators:  If I've got particular issues around the characters you mention I'd be thinking they are being treated as operators somewhere in the code.  And what I'm getting isn't a "string" but an object like a DateTime or Double or something.
3)  Dev Environment:  I'd suspect the coder was maybe coding toward Mono on Linux or something and it's a compiler or other issue.

Based just on what you posted, I had zero issue splitting those lines of text and converting the third element to an Int.  But I'm "seeing" plain text in English - I'm not seeing all the other factors that could be in play here.
0
JimiJ13I T ConsultantAuthor Commented:
d_york,

You are correct. I traced the issue on the Dot Net coding that concatenated the string thereby resulted to erroneous data extraction.  
 

Thanks.
0
JimiJ13I T ConsultantAuthor Commented:
Thanks for the quick response.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.