某文件名为“.txt”,其中可能由若干个英文单词组成。将此文件名改为“*.dat”,并且单词之间用下划线连接,例如: hello world.txt,改为hello_world.dat
//某文件名为"*.txt",其中*可能由若干个英文单词组成,将此文件名改为"*.dat",
//并且单词之间用下划线连接,例如:hello world.txt,改为hello_world.dat
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
public static void Main(string[] args)
{
string filename = @"hello world.txt", extendName = "dat";
int index = filename.LastIndexOf('.');
filename = filename.Substring(0, index + 1);
string[] splitFilename = filename.Split(' ');
filename = string.Join("_",splitFilename);
filename += extendName;
Console.WriteLine(filename);
}
}
}