Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: How to short string ?


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 4 - Last Post: Apr 3, 2017 12:39 PM Last Post By: Remy Lebeau (Te...
aidan levy

Posts: 31
Registered: 7/6/16
How to short string ?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 2, 2017 4:14 AM
Hi !
I have 2 Strings Dest and Source . I have #include <System.SysUtils.hpp> but when I use StrLCopy(Dest, Source,10); I receive error : no matching function for call to 'StrLCopy' System.SysUtils.hpp(2632): candidate function not viable: no known conversion from 'String' (aka 'System::UnicodeString') to 'System::WideChar *' (aka 'char16_t *') for 1st argument

What I need to for just short string ?
Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: How to short string ?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 2, 2017 4:38 AM   in response to: aidan levy in response to: aidan levy
El 02/04/2017 a las 13:14, aidan levy escribió:
Hi !
I have 2 Strings Dest and Source . I have #include <System.SysUtils.hpp> but when I use StrLCopy(Dest, Source,10); I receive error : no matching function for call to 'StrLCopy' System.SysUtils.hpp(2632): candidate function not viable: no known conversion from 'String' (aka 'System::UnicodeString') to 'System::WideChar *' (aka 'char16_t *') for 1st argument

What I need to for just short string ?


StrLCopy needs wchar_t* parameters and you must allocate the buffer for the characters first:

    Dest.SetLength(10);
    StrLCopy(Dest.c_str(), Source.c_str(), 10);

or you can use the SubString method from the String class

    Dest= Source.SubString(1, 10);
aidan levy

Posts: 31
Registered: 7/6/16
Re: How to short string ?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 2, 2017 5:04 AM   in response to: Antonio Estevez in response to: Antonio Estevez
Antonio Estevez wrote:

    Dest= Source.SubString(1, 10);
Thanks Antonio !

Work good , just corrected to SubString(0, 10);
Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: How to short string ?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 2, 2017 8:42 AM   in response to: aidan levy in response to: aidan levy
El 02/04/2017 a las 14:04, aidan levy escribió:
Antonio Estevez wrote:

    Dest= Source.SubString(1, 10);
Thanks Antonio !

Work good , just corrected to SubString(0, 10);

String class mimics the Delphi string type which is 1-index based: The index of the first char is 1

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: How to short string ?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 3, 2017 12:39 PM   in response to: Antonio Estevez in response to: Antonio Estevez
Antonio wrote:

String class mimics the Delphi string type which is 1-index
based: The index of the first char is 1

What you say is technically true. However, the code Aidan showed will work
fine, too. If you pass a starting index < 1, SubString() will silently change
it to 1.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02