MultiRecordEngine字符串的末尾包含定界字符 [英] MultiRecordEngine the end of the String Contains the delimited Character

查看:80
本文介绍了MultiRecordEngine字符串的末尾包含定界字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

我的琴弦看起来像这样:
你好;世界;

我课程的属性是DelimitedRecord(;")

现在我又得到了2个字段.

你好
世界;

我如何裁切;"从硬道理开始.

最好的问候Alex!

Hi!

My Strings look like this:
Hello; World;

The Attribute of my class is DelimitedRecord(";")

Now i get 2 Fields back.

Hello
World;

How i can cut the ";" from the last word.

Best Regards Alex!

推荐答案

您可以调用string.TrimEnd('';'').

You can call string.TrimEnd('';'').

string mystring = "Hello;";

string mystring = mystring.TrimEnd(';');

// Output is "Hello"
Console.WriteLine(mystring);


您也可以这样做,
You can do like this also,
string s= "World;";

s = s.Remove(s.Length-1);


好吧,如果您编写了该类并使用了DelimitedRecord(string)...如果我是您,并且您不希望返回任何空的拆分结果...我会在类中更改您的方法,因此您不必每次都进行处理.

Well, if you wrote the class and the attibute DelimitedRecord(string)... if I were you and you do not want to return any empty split results... I would change your method in the class so you don''t have to handle that every time.

public string DelimitedRecord(char delimiterChar)
{
   return mystring.TrimEnd(delimiterChar).Split(delimiterChar);
}


这篇关于MultiRecordEngine字符串的末尾包含定界字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆