String is the most basic data type in a variety of programming languages. It has been overwhelmed by other classes for a long time and is often disassociated (Substring, Split), torn (Join )...
Now the string is about to turn over and make a revolution. It is almost omnipotent. You can do whatever you want to, and other types of fear...
Let's take a look at what string has done after the revolution?
1. Open a file or website
1 "c: \ t.txt". Open ();
2 "http://www.cnblogs.com/ldp615/". Open ();
How can we do this? Look at the extension. It is very simple to directly call the Process. Start function:
1 public static void Open (this string s)
2 {
3 Process. Start (s );
4}
Only opening a file and stealing others' information is a preliminary operation. Strings can also be modified, deleted, or created (or directory)
2. file and directory operations
1 @ "C: Directory". CreateDirectory ();
2 @ "C: Directoryeadme.txt". WriteText ("this file is created by string! ");
3 @ "C: abc.txt". DeleteFile ();
The implementation is as simple as calling the File and Directory classes. The implementation of the above three extensions is as follows. (Of course, more file and directory operations can be implemented, which is very simple and will not be provided !)
1 public static void CreateDirectory (this string path)
2 {
3 Directory. CreateDirectory (path );
4}
5 public static void WriteText (this string path, string contents)
6 {
7 File. WriteAllText (path, contents );
8}
9 public static void DeleteFile (this string path)
10 {
11 if (File. Exists (path) File. Delete (path );
12}
I still feel uncomfortable. It is too troublesome to use one of the above files to delete the entire hard disk. No problem. See the following:
3. Execute the doscommandFirst, let's look at two simple
1 string output1 = "del c: \ t1.txt". Ex