Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract portion of a field string

Status
Not open for further replies.

guava65

Programmer
Jul 20, 2001
238
US
I would like to create a string that contains a portion of other strings.

For example:

first three letters of field1 + first three letters of field 2.

I'm sure this is very simple but I can't seem to find info on it in the help files.

Using Deplhi 5.0 professional

Mahalo,
cg
 
Try this:

startpos := 1;
numchars := 3;
NewString:= copy(String1,startpos,numchars) + copy(String2,startpos,numchars) + copy(String3,startpos,numchars);

The COPY function requires a string, the char position to start the extraction, and the number of characters.

If you mean extracting field names, and using those fields, then:
startpos := 1;
numchars := 3;
I := 0;
Info := '';
with MyDB do begin
for I := 0 to FieldCount -1 do
Info := Info + copy(Fields.FieldName,startpos,numchars);
end; {with}

Hope that helps.

Chris ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top