UnicodeString::Delete Method

99封情书 提交于 2020-01-14 06:21:47

问题


I have a Unicode string that I want to limit to 30 characters. I populate the string from a query, so I don't know the length to begin with. I want to simply snip off all of the characters past 30. I found the UnicodeString::Delete() method, but I don't know how to use it.

I tried this to no avail:

mystring = <code here to populate the unicode string mystring>
Delete(mystring, 30, 100);

回答1:


You are actually trying to call System::Delete(), which is not available to C++, only to Delphi. Internally, UnicodeString::Delete() calls System::Delete() using this as the string to manipulate.

UnicodeString::Delete() is a non-static class method. You need to call it on the string object itself, not as a separate function. Also, Delete() is 1-indexed, not 0-indexed:

mystring.Delete(31, MaxInt);

If you want to use 0-indexing, use UnicodeString::Delete0() instead:

mystring.Delete0(30, MaxInt);

However, the UnicodeString::SetLength() method would be more appropriate in this situation:

if (mystring.Length() > 30)
    mystring.SetLength(30);

Alternatively, you can use UnicodeString::SubString()/UnicodeString::SubString0():

mystring = mystring.SubString(1, 30);

mystring = mystring.SubString0(0, 30);


来源:https://stackoverflow.com/questions/51623840/unicodestringdelete-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!