2011-10-15 62 views

回答

3

有幾種方法可以做到這一點。這裏有幾個例子...

使用Split

string[] parts = abc.Split(new char[]{'='}, 2); 
if (parts.Length != 2) { /* Error */ } 
string result = parts[1].TrimStart(); 

使用IndexOfSubstring

int i = abc.IndexOf('='); 
if (i == -1) { /* Error */ } 
string s = abc.Substring(abc, i).TrimStart(); 

使用正則表達式(可能是矯枉過正此):

Match match = Regex.Match(abc, @"=\s*(.*)"); 
if (!match.Success) { /* Error */ } 
string result = match.Groups[1].Value; 
5
string abc="Your name = Hello World"; 
abc.Substring(abc.IndexOf("=")+1); //returns " Hello World" 
0
string newstring = abc.Substring(abc.IndexOf("=") + 2); 
0
string abc="Your name = Hello World"; 
    string[] newString = abc.Split('='); 
    /* 
     newString[0] is 'Your name ' 
     newString[1] is ' Hello World' 
    */ 
相關問題