ASP. NET string substitution, intercept, and start intercept from the last character in the string

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.