Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Pascal
Expertise: Beginner
Oct 28, 1998



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Selecting and Moving Parts of a String

I have two TField400s. The first TField400 contains the value "12345678" and other TField400 contains the value "11111111". I want to move the "5678" from the first TField400 and place it in the second TField400 so the value in the second TField400 will be "11115678" instead of "11111111".

To accomplish this task, just use the Copy function for handling strings.

//Grab the string field values
S1 := MyTable.FieldByName('Field1').AsString;
S2 := MyTable.FieldByName('Field2').AsString;

//Now copy the first four bytes of Field2 and concatenate 
the second four bytes of Field1 to it.
MyTable.FieldByName('Field2').AsString := 
Copy(S2, 1, 4) + Copy(S1, 5, 4);
Copy takes three parameters. The first is a string value, the second is the index to start copying from, and the third is the number of bytes to copy.
DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date