dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


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

WEBINAR:

On-Demand

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


Selecting and Moving Parts of a String

Question:
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".

Answer:
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.

 

 

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