Home > Back-end >  C builder 2010 how to repeat characters
C builder 2010 how to repeat characters

Time:10-19

A, I have A text content is "012345031", how to repeat characters to the inside, finally the contents of A text is "012345", what kind of function, it is best to give the complete code, thank you

CodePudding user response:

The removal of duplicate values, STL algorithms,

# include "string"
# include "Algorithm"

Char * STR="012345031";
STD: : string result=STR;//the results
STD: : sort (result. The begin (), the result. The end ());
STD: : string: : iterator newlast=STD: : unique (result. The begin (), the result. The end ());
Result. Erase (newlast, result end ());

CodePudding user response:

If there are Chinese characters, to use the UnicodeString or WideString

UnicodeString STR=L "characters have repeat here, to remove duplicate characters";
UnicodeString result=STR. C_str ();//a copy of
WideChar * start=result. C_str ();
WideChar * end=start + result in Length ();
STD: : sort (start, end);
WideChar * newlast=STD: : unique (start, end);
Result. SetLength (newlast - start);//has been duplication,

ShowMessage (L source string: "" + STR + L" \ n removal after repeated: "+ result);

CodePudding user response:

If the contents of A text is A EDIT is edt1 - & gt; The Text; Lb8 display with the tag as a result, how to write the code, I changed to
 char * STR=edt1 - & gt; The Text;//here I changed to use text box, it can not run 
STD: : string result=STR;//the results
STD: : sort (result. The begin (), the result. The end ());
STD: : string: : iterator newlast=STD: : unique (result. The begin (), the result. The end ());
Result. Erase (newlast, result end ());
Lbl8 - & gt; Caption=the result;

Don't run!

CodePudding user response:

 # include & lt; String> 
#include

Void __fastcall TForm1: : Button1Click (TObject * Sender)
{
STD: : string result=Edit1 - & gt; The Text. The c_str ();
STD: : sort (result. The begin (), the result. The end ());
STD: : string: : iterator newlast=STD: : unique (result. The begin (), the result. The end ());
Result. Erase (newlast, result end ());
Caption=result. C_str ();
}

CodePudding user response:

The upstairs code no problem

CodePudding user response:

If you want to write a custom function how to write ah, it is best to have a note in Chinese
  • Related