MID$

Talk about making games.

MID$

Postby Marko » Wed Nov 23, 2005 10:38 pm

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
Marko
 
Posts: 17
Joined: Sun Oct 09, 2005 9:44 am
Score: 0 Give a positive score

Postby makslane » Thu Nov 24, 2005 1:59 am

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);
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby regis » Wed May 03, 2006 12:46 pm

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
Many thanks,
Regis
regis
 
Posts: 48
Joined: Tue Nov 09, 2004 10:51 am
Location: France
Score: 1 Give a positive score

Postby DilloDude » Thu May 04, 2006 1:30 am

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.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby regis » Fri May 05, 2006 9:24 am

Many thanks (I suppose there is a mix between "letter" and "nam" in the 1st strcpy, but your solution works).
:D Regards
Regis
Many thanks,
Regis
regis
 
Posts: 48
Joined: Tue Nov 09, 2004 10:51 am
Location: France
Score: 1 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest