avc-acaldfald
c#里怎样才能将上面的字符串截取"-"以后的啊?即要得到acaldfald

解决方案 »

  1.   

    String.Substring 方法名称 说明 
    String.Substring (Int32)         从此实例检索子字符串。子字符串从指定的字符位置开始。 
    String.Substring (Int32, Int32) 从此实例检索子字符串。子字符串从指定的字符位置开始且具有指定的长度。举例如下:using System;
    using System.Collections.Generic;
    using System.Text;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                string s = "Hello C# World!";
                //s1为从s中截取的位置为3的字符以后的字符子串,3表示子字符串的起始字符位置
                string s1=s.Substring(3);
                Console.WriteLine(s1);
                //s2为从s中截取的位置为6的字符开始长度为2的字符串,6表示子字符的起始字符位置,2表示子字符长度
                string s2 = s.Substring(6, 2);
                Console.WriteLine(s2);
            }
        }
    }
    结果如下:lo C# World!C#这是好代码
      

  2.   

            string a = "avc-acaldfald";
            a = a.Substring(a.IndexOf('-')+1, a.Length - a.IndexOf('-')-1);
      

  3.   

        string a = "avc-acaldfald";
                a = a.Replace("-","");
      

  4.   

    string str = "avc-acaldfald";
    str = str.Substring(str.IndexOf('-')+1, str.Length - str.IndexOf('-')+1);
      

  5.   


    更正下:
    string str = "avc-acaldfald"; 
    str = str.Substring(str.IndexOf('-')+1, str.Length - str.IndexOf('-')-1);
      

  6.   

    using System;
    using System.Collections.Generic;
    using System.Text;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                string s = "Hello C# World!";
                //s1为从s中截取的位置为3的字符以后的字符子串,3表示子字符串的起始字符位置 
                string s1 = s.Substring(3);
                Console.WriteLine(s1);
                //s2为从s中截取的位置为6的字符开始长度为2的字符串,6表示子字符的起始字符位置,2表示子字符长度 
                string s2 = s.Substring(6, 2);
                Console.WriteLine(s2);
                string s3 = s.Substring(s.IndexOf("o") + 1, s.Length - s.IndexOf("o") - 1);
                Console.WriteLine(s3);
            }
        }
    }
    这种么 用8楼的方法不错。