开发者

Convert text to xml

I want to convert a tab del开发者_StackOverflow社区imited text file to a XML file. I was able to do it with a single character delimiter. But how do i extend it to tabs? I am coding in C# and using Visual Studio 2010.


A tab is a single character, written as '\t'. Try adapting your existing solution to use that. If that doesn't work, post more details about your approach and the problems you encountered.


Basically you want to split your lines using the tab char? In that case, use the method you already have and use \t for splitting.


Are the tabs an \t symbol? Then the task is, basically, the same. If by tabs you mean multiple spaces, you might want to delete the extra spaces. A simple way is to use a regex:

  string input = "This is   text with   far  too   much   " + 
                 "whitespace.";
  string pattern = "\\s+";
  string replacement = " ";
  Regex rgx = new Regex(pattern);
  string result = rgx.Replace(input, replacement);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜