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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String Manipulation

Status
Not open for further replies.

Binksy

Programmer
Nov 23, 2000
7
GB
i have been trying (unsuccessfully) to get the last character of a string using STRLEN. The string is a postcode(UK) which consists of numbers and chars. How do i get delphi to read the string backwards. I am using delphi 2.0.

Many thanks - Binksy
 
Delphi , and pascal.. manage their strings as arrays...
so ig you have for example..

s:='hello';

and you what to access the 'o' you would do
a:=s[4]; or a:=s[strlen(s)-1];
 
You people confusing pascal with c, there is no strlen(string) in pascal, but length(string) which returns you the length of the string. To read backwards,

for i:=length(_string_) downto 1 do
write(_string_);

and if you have s:='hello'; _char_:=s[5] gives 'o';
Best Regards,

aphrodita@mail.krovatka.ru {uiuc rules}
 
What i need precisely is the last digit or digits of the first section of the british post code system:

BB1 4HU
^ and
BB12 4HU
^^

are valid post codes but give very different results, when the user inputs the postcode, they enter it as one chunk:

"Postcode: BB124HU"

is there anyway to do this without IF statements?


 
As Aphrodita mentioned, in Pascal,
MyChar := Copy(MyString, Length(MyString), 1)
returns the last character in MyString. If this
is not working, you may have hidden characters
which should be removed first as in:
MyChar := Copy(Trim(MyString), Length(MyString), 1)

If doing this in C/C++, remember that Pascal String
has first character at [1], not [0].
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top