String tmpString = @"C:\Documents and Settings\Administrator\My Documents\My Pictures\";String fullString = @"C:\Documents and Settings\Administrator\My Documents\My Pictures\1.gif";String myString = fullString.Substring(tmpString.Length).ToString();

解决方案 »

  1.   

    string str = “C:\Documents and Settings\Administrator\My Documents\My Pictures\1.gif“;
    int i = str .LastIndexOf('\');string strResult = st.Substring(i);
      

  2.   

    veaven(风林火山)兄弟的代码执行起来有些问题(改 “为", ”为",string strResult=str.Substring(i)后)。
    JohnnyDJ(人不来车不往)兄弟,我另外还向请教一下,如果C:\Documents and Settings\Administrator\My Documents\My Pictures\1.gif是从某个TextBox或File Field里面读取的话,那不是确定不了C:\Documents and Settings\Administrator\My Documents\My Pictures\。
      

  3.   

    string str = "C:\\Documents and Settings\\Administrator\\My Documents\\My Pictures\\1.gif";
               int i = str .LastIndexOf('\\');
               string strResult = str.Substring(i);
      

  4.   

    应改为:
    string str = "C:\\Documents and Settings\\Administrator\\My Documents\\My Pictures\\1.gif";
               int i = str .LastIndexOf('\\');
               string strResult = str.Substring(i+1);
      

  5.   

    还有一个问题:在那些框框里面读取不到“C:\\Documents and Settings\\Administrator\\My Documents\\My Pictures\\1.gif”这样的字符呀。
      

  6.   

    private void button1_Click(object sender, System.EventArgs e)
    {
    openFileDialog1.Filter = "位图文件(*.bmp)|*.bmp|图形转换格式(*.gif)|*.gif|JEPG文件(*.jpg;*.jpeg)|*.jpg;*.jpeg|图标文件(*.ico)|*.ico|图元文件(*.wmf)|*.wmf";
    openFileDialog1.RestoreDirectory = true;
    if(openFileDialog1.ShowDialog() == DialogResult.OK)
    {
    textBox1.Text=openFileDialog1.FileName;
    } /*
    String tmpString = @"C:\Documents and Settings\Administrator\My Documents\My Pictures\"; String fullString = @"C:\Documents and Settings\Administrator\My Documents\My Pictures\1.gif"; String myString = fullString.Substring(tmpString.Length).ToString();
    label1.Text=myString; 
    */
       string str=textBox1.Text;
               string str1 = "C:\\Documents and Settings\\Administrator\\My Documents\\My Pictures\\1.gif";
               int i = str .LastIndexOf("\\");
               string strResult = str.Substring(i+1);
    label1.Text=strResult; }