从长字符串中删除一个字符

Remove a character from a long string

我有以下字符串:

https://example.com/get/ea34b8062cr2533eed0b4302e44d4090e26ae3c01bb1124292f3c970_1280.jpg

我只想从此部分 https 中删除字符 s 并再次 return 整个字符串,但不包含 s 字符。

wxString imgURL = "https://example.com/get/ea34b8062cr2533eed0b4302e44d4090e26ae3c01bb1124292f3c970_1280.jpg";
imgURL.Remove(imgURL.find('s'));
this->m_textShowData->SetValue(imgURL);

不幸的是,前面的代码删除了 s 字符,但没有再次 return 整个字符串,而是仅 returns http

如何删除字符 s 然后 return 没有该字符的整个字符串?

只需使用擦除功能:

 imgURL.erase(4,1);

根据 the documentationRemove() 函数有重载,您可以在其中指定要从给定位置删除的字符数。
所以这应该可以解决问题:

imgURL.Remove(imgURL.find('s'), 1);

但仅出于兼容性原因保留此功能,正如文档中提到的那样,不应在新代码中使用它。请查看 erase() 函数,它与 Remove()

具有相同的语法