Page 1 of 1

MID$

PostPosted: Wed Nov 23, 2005 10:38 pm
by Marko
I've got a variable of a string type - Strvar

how could I write down only the third letter, for example, from Strvar?(MID$) :oops:

THNX

Marko

PostPosted: Thu Nov 24, 2005 1:59 am
by makslane
You can get the third letter by using this (If you need get a single letter):

char letter = Strvar[2]; //0 is the first letter

To copy to other string, try this:
char letter[2]; //0 will hold the letter, 1 will hold the end of string

letter[0] = Strvar[2];
strcpy(text, letter);

PostPosted: Wed May 03, 2006 12:46 pm
by regis
Looking at this topic, and trying to implement this solution leads to an error.
My problem is: I have a string variable: let say: NAME.
For instance, suppose NAME equals "andrew smith"
A would like to get the 1st letter of NAME and put it in the variable LETTER1 (also declared as s string in GE)
Unfortunately, the following code does not seem to work:
char LETTER1 = NAME[0];
Why? :?:
Many thanks for your help.
Regis

PostPosted: Thu May 04, 2006 1:30 am
by DilloDude
Try
Code: Select all
char nam[50];
char letter[1];
strcpy(letter, NAME);
letter[0] = nam[n];
strcpy(text, letter);

this will make the text display the nth character of NAME.

PostPosted: Fri May 05, 2006 9:24 am
by regis
Many thanks (I suppose there is a mix between "letter" and "nam" in the 1st strcpy, but your solution works).
:D Regards
Regis