How to pick one character from a string?

General discussion on mikroPascal.
Post Reply
Author
Message
Moas
Posts: 25
Joined: 14 Apr 2009 19:50

How to pick one character from a string?

#1 Post by Moas » 14 Apr 2009 20:00

Hello everybody!
Could you please help me with the chunk of code that would cut out a character from specified position of a string variable?

For example I have declared

Code: Select all

var
Slovo : string [10];
Pismeno : byte;
And I would like to cut out the third (or any else) character from left from the "Slovo" and store it in the "Pismeno".

All methods I was able to prepare were too complex and too memory-consuming. I am sure there is a way to do this nicely. Maybe even a standard command which I overlooked... :roll: Yet I am not able to figure that out. :( I went through last 20 pages of this forum and found no answer.

Thank you!

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

#2 Post by janni » 15 Apr 2009 01:09

You could use StrRemoveChr procedure from a library presented here http://www.mikroe.com/forum/viewtopic.php?t=11873. First you should store the character by simple assingment Pismeno:=Slovo[2] (third char has index 2).

Moas
Posts: 25
Joined: 14 Apr 2009 19:50

#3 Post by Moas » 15 Apr 2009 05:57

janni wrote:a replacement for the official strings library for PIC18
Thanks janni for this hint, but is there a way to do this for PIC16? :oops:

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

#4 Post by Dany » 15 Apr 2009 09:54

Moas wrote:
janni wrote:a replacement for the official strings library for PIC18
Thanks janni for this hint, but is there a way to do this for PIC16? :oops:
Hi, please have a look at http://users.edpnet.be/rosseel01/DRO/PI ... Utils.mpas, procedures copy and delete.
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Moas
Posts: 25
Joined: 14 Apr 2009 19:50

#5 Post by Moas » 15 Apr 2009 18:50

Hi Dany, thanks a million for this, I will try the "Copy" command which should be exactly what I am looking for! :D

Post Reply

Return to “mikroPascal General”