Fog Creek Software
Discussion Board




I have a question for delphi programmers..

Lets say I have an integer value  12345, and I need to say the 4th number... Well, it would be 4, (after using div, mod functions...etc). I know that :)
The question is so: i have a string in edit1 field "abcde", how to say the 4th character??? Which function should I use to? Can someone help me?


thnx

Donatas
Thursday, October 17, 2002

Well...

Edit1.Text holds the string in question, and Edit1.Text[4] holds the fourth character.

Delphi string indices are 1-based, a holdover from Pascal.

Anthony Mills
Thursday, October 17, 2002

Just want to add to that - don't forget to check the length of the string before accessing an element of the string using [4].

An alternative is to use the Copy function, which will return an empty string if out of bounds, which may or may not be better in your case.

Big B
Thursday, October 17, 2002

*  Recent Topics

*  Fog Creek Home