本文介绍了string.split方法未在定界符之间给出空字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我正在使用string.split方法拆分字符串

例如我有以下字符串

61a | a62a | a63a | aa | a65a | a

您看到63之后应该有一个空字符串要返回,但不是,我该怎么做,请帮我

hello,

I am splitting the string using string.split method

for example i have the following string

61a|a62a|a63a|aa|a65a|a

you see after 63 there should be an empty string to be returned but its not, how can i do that please help me

推荐答案


private void ReadFileData(string path)
{
    string line;
    string[] delimiters = new string[] { "a|a" };
    try {
        using (StreamReader file = new StreamReader(path))
        {
            while ((line = file.ReadLine()) != null)
            {
                string[] parts = line.Split(delimiters, StringSplitOptions.None);
                WriteDateToSQL(parts);
            }
            file.Close();
        }
    }
    catch (Exception e) {
        MessageBox.Show(e.ToString());
    }
}




祝一切顺利.
--Amit




All the best.
--Amit


string str = "61a|a62a|a63a|aa|a65a|a";
var strarray = str.Split(new string[] { "a|a" }, StringSplitOptions.None);


这篇关于string.split方法未在定界符之间给出空字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 01:09