Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 840 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
strings #271885
06/15/09 15:10
06/15/09 15:10
Joined: Jan 2006
Posts: 33
California
Amanda_Dearheart Offline OP
Newbie
Amanda_Dearheart  Offline OP
Newbie

Joined: Jan 2006
Posts: 33
California
If I create a string such as

String *MyString = "Hi out there"

is there a way I can retrieve individual characters such as
the letter H, and then the letter i, and then the letter o, etc. etc. etc.

Also does the string support concatenation, such as

Mystring = String1 + String2

thanks for any help!


Prepare to be assimilated. Resistance is futile

Amanda Dearheart

Business E-mail : cjw.roberson@gmail.com
Re: strings [Re: Amanda_Dearheart] #271889
06/15/09 15:18
06/15/09 15:18
Joined: Jul 2004
Posts: 1,710
MMike Offline
Serious User
MMike  Offline
Serious User

Joined: Jul 2004
Posts: 1,710
It does support concatenation, but not that way, as i know.
For that you use the Gs function: str_cat( string to pointer, string from pointer)
the string from pointer can be like this.. str_cat(str1,"second text added");

to retrieve individual chars, you can use str_trunc and clip, manipulations, though i think there might be a high chance ( i didnt explore yet) about char[char-number] options.

Re: strings [Re: MMike] #271989
06/15/09 23:25
06/15/09 23:25
Joined: Apr 2006
Posts: 737
Ottawa, Canada
O
Ottawa Offline
User
Ottawa  Offline
User
O

Joined: Apr 2006
Posts: 737
Ottawa, Canada
Hi!

I used str_clip at one point.

I transfered all the letters of the string to numbers
put the numbers in an array

and then I used: if the number is ....


Ottawa smile

Re: strings [Re: Ottawa] #271995
06/16/09 00:20
06/16/09 00:20
Joined: Aug 2003
Posts: 902
Van Buren, Ar
Gordon Offline
User
Gordon  Offline
User

Joined: Aug 2003
Posts: 902
Van Buren, Ar
or you could use this little function cool

Code:

#include <acknex.h>

STRING* str1="This is a Test";

char GetChar(STRING* str, int chr)
{
	return((str.chars)[chr]);
}


void main()
{
	wait(1);
	char c;
	
	c = GetChar(str1,0);
	if (c == 'T') {	
		error("passed");
	} else {
		error("fail");
	}
}



Our new web site:Westmarch Studios
Re: strings [Re: Gordon] #272190
06/16/09 21:01
06/16/09 21:01
Joined: Jun 2009
Posts: 27
Bosnia and Herzegovina, Saraje...
C
CharlieAmer Offline
Newbie
CharlieAmer  Offline
Newbie
C

Joined: Jun 2009
Posts: 27
Bosnia and Herzegovina, Saraje...
you may treat a string as a array of chars with length (size) of strlen() .
so, if you have a something like this:

STRING* strng="HELLO";

than function strlen(strng) will return 5.
to access first letter u use strng[0], second letter strng[1], .. etc, fifth letter strng[4];
so don't access a string like array from 1 to strlen(). access it like array from 0 to strlen()-1;

Re: strings [Re: CharlieAmer] #272321
06/17/09 13:24
06/17/09 13:24
Joined: Aug 2003
Posts: 902
Van Buren, Ar
Gordon Offline
User
Gordon  Offline
User

Joined: Aug 2003
Posts: 902
Van Buren, Ar
Quote:
to access first letter u use strng[0], second letter strng[1]


While this will work in C for a char array it will NOT work in lite-c.

STRING is defined in atypes.h as
Code:
typedef struct STRING {
	C_LINK	link;
	char	*chars;		// pointer to null terminated string
	long	length;		// allocated length of string
	long	flags;		// see STRF_... above
    byte    pad[PAD_STRING];
} STRING;


Therefore you must access the character data as (strname.chars)[index]. The first character is index = 0 etc. Just remember that STRING* is not the same as char*.


Our new web site:Westmarch Studios

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1