zoukankan      html  css  js  c++  java
  • C# 字符串的截取和替换

    1、取字符串的前n个字符

    (1)string str1=str.Substring(0,n);

    (2)string str1=str.Remove(i,str.Length-n);

    2、去掉字符串的前n个字符

    string str1=str.Remove(0,n);

    string str1=str.SubString(n);

    3、从右边开始取n个字符:

    string str1=str.SubString(str.Length-n);

    string str1=str.Remove(0,str.Length-n);

    4、从右边开始去掉n个字符:

    string str1=str.Substring(0,str.Length-n);

    string str1=str.Remove(str.Length-n,n);

    5、如果字符串中有"abc"则替换成"ABC"
       str=str.Replace("abc","ABC");

    6、c#截取字符串最后一个字符的问题

    str1.Substring(str1.LastIndexOf(",")+1);

     

    7、C# 截取字符串最后一个字符

    str = str.Substring(str.Length-1, 1);

  • 相关阅读:
    非常可乐
    Find The Multiple
    盲点集锦
    Fliptile
    Catch That Cow
    Dungeon Master
    hdoj 1045 Fire Net
    hdoj 1342 Lotto【dfs】
    zoj 2100 Seeding
    poj 3620 Avoid The Lakes【简单dfs】
  • 原文地址:https://www.cnblogs.com/dt520/p/5762025.html
Copyright © 2011-2022 走看看