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

后端 未结 8 1355
有刺的猬
有刺的猬 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:03

    You need to check your statement like this :

    string url = "www.example.com/aaa/bbb.jpg";
    string lenght = url.Lenght-4;
    if(url.Lenght > 15)//eg 15
    {
     string newString = url.Substring(18, lenght);
    }
    

提交回复
热议问题