Realize the effect
Only one semicolon is assigned after each item.
Pass in;abc;123;jkl; Return abc;123;jkl; //Eliminate the problem that the first bit of the string is a semicolon
Pass in abc;;;123;;jkl; returns abc;123;jkl; //Eliminate, the item in the string is followed by an extra semicolon;
Pass in abc;;;123;;jkl Return abc;123;jkl; //Fill the string at the last item of the string
Key functions
Delete {Function Description: Delete the specified string in the string. This function has three parameters. The first parameter is the string to be processed, the second parameter is where to start deletion, and the third parameter is the number of characters to be deleted. }LeftStr(unit: StrUtils) {Function description: Returns the new character (string) specified on the left side of the string. This function has two parameters. The first parameter is the complete string, and the second parameter is the specified number. }RightStr(unit: StrUtils) {Function description: Returns the new character (string) specified to the right of the string. This function has two parameters. The first parameter is the complete string, and the second parameter is the specified number. }Pos {Function description: Find the location of the character (string). This function has two parameters. The first parameter is the character (string) to be searched, and the second parameter is the character (string) to be searched. } Code:// uses required
StrUtils Unit function DealStr(s:string):string;var s2,s3:string;var s1:widestrng; //If the string to be processed has a man, the widestrng type should be used, begin s1:=''; s2:='' ; s3:=''; s1:=s; if not (s1='') then begin while Pos(' ',s1)>0 do //Eliminate all spaces in the string begin Delete(s1,Pos(' ', s1),1); end; if rightstr(s1,1)<>';' then // Add ';' at the end of the string to ensure the data integrity of the loop begin s1:=s1+';'; end; while (Length(s1)>0) do //Detection until the string s1 is 0 begin if Pos(';',s1)=1 then //Display whether the first bit is ';' begin s1:=RightStr( s1, (Length(s1)-Pos(';',s1)) ); end; s3:=LeftStr(s1,Pos(';',s1));//Take the string on the left if (s3=' ;')then //If the string on the left has only a semicolon, discard begin end else begin s2:=s2+s3; //Accumulate the string end that conforms to the rules; s1:=RightStr(s1, (Length(s1) -Pos(';',s1)) ); end; end; Result:=s2;end;