【问题标题】:How to rearrange the string in C#如何在 C# 中重新排列字符串
【发布时间】:2021-08-24 03:33:05
【问题描述】:

\在我的 csv 文件中有两行数据: \a;b;c;d;e; \1;2;3;4;5; \如何在 c# 中如下所示: \a=1;enter code here \b=2;enter code here \c=3;enter code here \d=4;enter code here \e=5;enter code here

【问题讨论】:

    标签: streamreader


    【解决方案1】:

    tldr;你拆分了文本。

    1. 从 csv 获取字符串 //例如字符串 originalTxt = @"\a;b;c;d;e;\1;2;3;4;5";
    2. 拆分行
    3. 重新排列/编辑每行中的每个单词
    4. 结合
    string resultTxt = "";
    string mycodehere ="enter code here ";
    string originalTxt = ...; //TODO :: your code for get text from csv 
    string[2] rows = originalTxt.Split('\');   // split the \ got 2 rows 
    string[] row1 = rows[0].Split(';');    //split each word
    string[] row2 = rows[1].Split(';');    //split each word
    for(int i= 0 ; i< row1.Count ; i++){
         resultTxt  +=  @"\" + row1[i] + "=" + row2[i] + ";" + mycodehere + " " ; 
    }
     //TODO :: use resultTxt  
        
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-28
      • 2015-08-08
      • 2011-04-15
      • 2018-10-05
      • 1970-01-01
      • 1970-01-01
      • 2012-09-03
      • 1970-01-01
      相关资源
      最近更新 更多