比如[email protected]   把这个字符串按照@分割开,把@前后的字符串分别赋值给a和b 该怎么做呢?

解决方案 »

  1.   

    string[] arr = yourstring.Split('@');
    a = arr[0];
    b = arr[1];
      

  2.   

    string[] str="[email protected]".Slipt('@');
    a=str[0];
    b=str[1];
      

  3.   

    string str="[email protected]";
    string[]result = str.Split("@".ToCharArray());
    a=result[0];
    b=result[1];
      

  4.   

    string[] arr = yourstring.Split(new char[]{','});
    a = arr[0];
    b = arr[1];
      

  5.   

    string[] arr = yourstring.Split(new char[]{'@'}); 
    a = arr[0]; 
    b = arr[1];
      

  6.   

    String s = "[email protected]";
    String[] arr=s.Split(new String[]{"@"},StringSplitOptions.None);
    String a = arr[0]; 
    String b = arr[1];
      

  7.   

        string str = "[email protected]";
            int index = str.IndexOf("@");
            string a = str.Substring(0, index);
            string b = str.Substring(index + 1);
      

  8.   


    String s = "[email protected]"; 
    String[] arr=s.Split(new String[]{"@"},StringSplitOptions.None); 
    String a = arr[0]; 
    String b = arr[1];
      

  9.   

    谢谢,解决。顺便再问下, 就比如:[email protected] 这个字符串是从别的页传过来的,我要怎么判断这个字符串里是否含有@呢?
      

  10.   

    if(字符串.IndexOf('@')!=-1)
    {
    //有
    }
    else
    {
    //没有
    }
      

  11.   

    Split 分成数组后 看看 数组lengh 阿 就能知道了
      

  12.   

    if (s.IndexOf('@') >= 0)
    {
      // s含有@
    }
    else
    {
      // s不含@
    }
      

  13.   

    string[] arr = yourstring.Split(new char[]{'@'}); 
    a = arr[0]; 
    b = arr[1];
      

  14.   

    我也来来.
    a=yourstring.ToString().Split('@')[0];
    b=yourstring.ToString().Split('@')[1];
      

  15.   


     string str = "[email protected]"; 
     int index = str.IndexOf("@"); 
     string a = str.Substring(0, index); 
     string b = str.Substring(index + 1);
      

  16.   

    String s = "[email protected]"; 
    String[] arr=s.Split(new String[]{"@"},StringSplitOptions.None); 
    String a = arr[0]; 
    String b = arr[1];