Sometimes you want to replace some characters with other characters in a string, what do I do?
For example:
string [email protected] "csks/news/user_top/qqqq/qqqq.jpg";
Image = Image. Replace ("/", @ "\"); Replace. Replace ("substituted character", "substituted character")
Response.Write (image); Output on the page
The output is csks\news\user_top\qqqq\qqqq.jpg .....
This allows you to replace part of the character ....
Here's how to intercept a few characters in a character
Similarly, a string of characters is defined first:
string [email protected] "csks/news/user_top/qqqq/qqqq.jpg";
Image = Image. Substring (0,3); Intercept. Substring (Intercept the 1th character from the first one is 0 and so on, where to intercept)
Response.Write (image); Output on the page
The result of the output is CSK ...
There is one way that I often use to intercept types that I like to use very much:
string image = @ "Csks/news/user_top/qqqq/qqqq.jpg";
Image = Image. Substring (image. LastIndexOf (".") + 1); Interception of LastIndexOf (e.g. ".") starts with the last "." In the string, and the back of add 1 is not intercepted.)
Response.Write (image);
Output is JPG
If you want to intercept a type that is not, you can also:
string image = @ "Csks/news/user_top/qqqq/qqqq.jpg";
Image = Image. Substring (image. LastIndexOf ("news/") + 5); Intercept LastIndexOf (from "news/" start interception, because the back +5 so "news/" the five characters are not in the range of interception, the following characters are intercepted)
Response.Write (image);
Output is user_top/qqqq/qqqq.jpg
ASP. NET string substitution, intercept, and start intercept from the last character in the string