C# - Substring: index and length must refer to a location within the string

后端 未结 8 1361
有刺的猬
有刺的猬 2020-12-05 23:31

I have a string that looks like

string url = \"www.example.com/aaa/bbb.jpg\";

\"www.example.com/\" is 18 fixed in length. I want to get th

8条回答
  •  暖寄归人
    2020-12-06 00:01

    Try This:

     int positionOfJPG=url.IndexOf(".jpg");
     string newString = url.Substring(18, url.Length - positionOfJPG);
    

提交回复
热议问题