Retrieving a Character from a String

Hello. How can I retrieve a particular character from a string?

For example, in English, I will specify:

set PHRASE as 'Pascal Programming'
get the fifth character from PHRASE

then the result should be A because the fifth character is an A.

How can I 'translate' this into Pascal? Thanks.

Comments

  • : Hello. How can I retrieve a particular character from a string?
    :
    : For example, in English, I will specify:
    :
    : set PHRASE as 'Pascal Programming'
    : get the fifth character from PHRASE
    :
    : then the result should be A because the fifth character is an A.
    :
    : How can I 'translate' this into Pascal? Thanks.
    :
    A string is an 1-indexed array of chars. This means that you can get a the i-th character from string S using the following code:
    [code]
    ch := S[i];
    [/code]
    in your case it would be:
    [code]
    ch := Phrase[5];
    [/code]
  • : : Hello. How can I retrieve a particular character from a string?
    : :
    : : For example, in English, I will specify:
    : :
    : : set PHRASE as 'Pascal Programming'
    : : get the fifth character from PHRASE
    : :
    : : then the result should be A because the fifth character is an A.
    : :
    : : How can I 'translate' this into Pascal? Thanks.
    : :
    : A string is an 1-indexed array of chars. This means that you can get a the i-th character from string S using the following code:
    : [code]
    : ch := S[i];
    : [/code]
    : in your case it would be:
    : [code]
    : ch := Phrase[5];
    : [/code]
    :

    I see. Thanks very much!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories