Gamestudio Links
Zorro Links
Newest Posts
ZorroGPT
by TipmyPip. 04/25/26 16:09
Z9 getting Error 058
by jcl. 04/24/26 17:48
Stooq now requires an API key
by jcl. 04/13/26 09:42
Strange "Alien" Skull created with >Knubber<
by NeoDumont. 04/10/26 18:58
400 free seamless texture pack downl. here !
by NeoDumont. 04/08/26 19:55
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
2 registered members (TipmyPip, Grant), 3,389 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
valino, juergenwue, VladMak, Geir, ondrej
19209 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Adding a char to a STRING* using str_getchr #343416
10/06/10 08:01
10/06/10 08:01
Joined: Mar 2006
Posts: 1,993
Karlsruhe
PadMalcom Offline OP
Serious User
PadMalcom  Offline OP
Serious User

Joined: Mar 2006
Posts: 1,993
Karlsruhe
Hi, what I'm trying to do is to add chars to a STRING.

I iterate trough a STRING and get each char using "str_getchr". The resulting char should be added to another STRING.

My code looks like:
Code:
int i = 1;
while(i<length(myString1)-1) {
  str_cat(myString2,_str(str_getchr(myString1,i)));
  i++;
}



Unfortunately, my result string (myString2) contains some stupid characters in between... Any ideas why?

Thanks in advance!

Re: Adding a char to a STRING* using str_getchr [Re: PadMalcom] #343483
10/06/10 15:57
10/06/10 15:57
Joined: Dec 2008
Posts: 271
Saturnus Offline
Member
Saturnus  Offline
Member

Joined: Dec 2008
Posts: 271
Howdy,

_str() converts a char array to STRING, but str_getchr() returns only a char (or rather a var), so this doesn't work.

You could do something like this instead:

str_cat(myString2, " ");
str_setchr(myString2, str_length(myString2), str_getchr(myString1, i));

Re: Adding a char to a STRING* using str_getchr [Re: Saturnus] #343484
10/06/10 16:00
10/06/10 16:00
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
This should also do the trick:
Code:
int i;
for(i=0; i<length(myString1)-1; i++) 
	str_cat(myString2, _str(&str_getchr(myString1, i)));




Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: Adding a char to a STRING* using str_getchr [Re: Saturnus] #343486
10/06/10 16:03
10/06/10 16:03
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Try this for size.... (untested of course)

Code:
for(i=0; i<length(myString1); i++)
{  str_cat(myString2, _str((myString1.chars)[i]));  }

//or

int i = 1;
while(i<length(myString1)-1)
{
  str_cat(myString2,_str( (myString1.chars)[i-1] ));
  i++;
}





"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | 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