If I have a line: str1|str2|str3|srt4 and str1|str2|str3|srt4 it with | as a delimiter. My output will be str1 str2 str3 str4 .
But if I have a line: str1||str3|str4 output will be str1 str3 str4 . I want my result to be like str1 null/blank str3 str4 .
Hope this makes sense.
string createText = "srt1||str3|str4"; string[] txt = createText.Split(new[] { '|', ',' }, StringSplitOptions.RemoveEmptyEntries); if (File.Exists(path)) { //Console.WriteLine("{0} already exists.", path); File.Delete(path); // write to file. using (StreamWriter sw = new StreamWriter(path, true, Encoding.Unicode)) { sw.WriteLine("str1:{0}",txt[0]); sw.WriteLine("str2:{0}",txt[1]); sw.WriteLine("str3:{0}",txt[2]); sw.WriteLine("str4:{0}",txt[3]); } }
Output
str1:str1 str2:str3 str3:str4 str4:"blank"
This is not what I am looking for. This is what I would like to code:
str1:str1 str2:"blank" str3:str3 str4:str4
source share