Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have strings like this:

    00123_MassFlow
    0022245_VOlumeFlow
    122_447_Temperature

I have to split these strings with _ using C#. _ may appear multiple places but i have to take last value.

My should be like this:

    MassFlow
    VOlumeFlow
    Temperature

How i can achieve this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.2k views
Welcome To Ask or Share your Answers For Others

1 Answer

"122_447_Temperature".Split('_').Last();

If you don't mind the extra overhead of creating an array and throwing away a bunch of strings. It won't be as fast as using LastIndexOf and Substring manually, but it's a ton easier to read and maintain, IMO.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...