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

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

string split in c#

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
"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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...