将字符串拆分为char并在C#中添加"......"

ani*_*nil 4 .net c# visual-studio-2010

我想将一个字符串拆分为char

那是我的字符串

"非常好的网站堆栈溢出"

我想转换这个字符串

喜欢

第一个单词和第二个单词分成字符

.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..溢出...... .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..

我正在使用自然的Reader软件并使用拼写制作听写mp3文件

那是我的计划

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace file
{
    class Program
    {


        public static string fileLoc = @"C:\Users\Administrator\Desktop\sample1.txt";
        public static string s;
       public static  string data = "the stack overflow in very good website";
        private static void Main(string[] args)
        {

            Create_File();
            Wrint_in_File();
            Read_file();
            add_comma();

            s = Console.ReadLine();

        }
        public static void Wrint_in_File()
        {
            if (File.Exists(fileLoc))
            {
                using (StreamWriter sw = new StreamWriter(fileLoc))
                {

                    sw.WriteLine(DateTime.Now);
                    sw.WriteLine(data);
                    Console.WriteLine("Data is successfully save in File");



                }
            }
        }
        public static void Create_File()
        {

            FileStream fs = null;
            if (!File.Exists(fileLoc))
            {
                using (fs = File.Create(fileLoc))
                {
                    Console.WriteLine(@"File is Successfully Created at  C:\Users\Administrator\Desktop\sample1.txt");
                     Console.ReadLine();
                }
            }
        }
        public static void Read_file()
        {
            if (File.Exists(fileLoc))
            {
                using (TextReader tr = new StreamReader(fileLoc))
                {
                    string s= tr.ReadToEnd();
                     Console.WriteLine(s);
                    Console.ReadLine();
                }
            }
        }

        public static void add_comma()
        {
            if (File.Exists(fileLoc))
            {
                using (StreamWriter sw = new StreamWriter(fileLoc))
                {

                    sw.WriteLine(DateTime.Now);
                    string txt =data.Replace(" ", ".. .. .. .. .. .. .. ..");
                    sw.WriteLine(txt);
                    Console.WriteLine(txt);
                }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Hab*_*bib 5

使用LINQ你可以做到:

string str = "the stock overflow in very good website";

string separator = "...";
string joinedString = string.Join("", (str.Split()
                      .Select(r=> r + separator +
                                   (string.Join(separator, r.ToCharArray()))
                                   +separator)));
Console.WriteLine(joinedString);
Run Code Online (Sandbox Code Playgroud)

(顺便说一下它的堆栈溢出)

输出将是:

所述...吨... H ... E ...库存内容S ...吨... O ...用C ... K ...溢出... O ...诉.. ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... [R ... Y ... ...好...摹的...的... ... d网站... W上...e.B内容S ...我...的... E. ..

(记得包括using System.Linq;)