Gamestudio Links
Zorro Links
Newest Posts
Z9 getting Error 058
by k_ivan. 04/20/26 15:57
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
ZorroGPT
by TipmyPip. 04/08/26 17:08
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
0 registered members (), 4,478 guests, and 11 spiders.
Key: Admin, Global Mod, Mod
Newest Members
juergenwue, VladMak, Geir, ondrej, mredit
19208 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
String length #200273
04/03/08 10:43
04/03/08 10:43
Joined: Oct 2003
Posts: 702
Z
zazang Offline OP
User
zazang  Offline OP
User
Z

Joined: Oct 2003
Posts: 702
Hi

I have an inkey code which accepts a name typed by a user into a string of length 30.Lets say I type a name of 20 characters and store it in this string.
Then this string becomes 20 charcaters long automatically which is very annoying because I want it to retain its original length of 30 characters.

In short is there a way to dynamically resize a string to a certain length ?

regards
zazang



I like good 'views' because they have no 'strings' attached..
Re: String length [Re: zazang] #200276
04/03/08 10:50
04/03/08 10:50
Joined: Jan 2004
Posts: 2,013
The Netherlands
E
Excessus Offline
Expert
Excessus  Offline
Expert
E

Joined: Jan 2004
Posts: 2,013
The Netherlands
Yes, with str_cpy() or str_cat().

Re: String length [Re: Excessus] #200279
04/03/08 11:01
04/03/08 11:01
Joined: Oct 2003
Posts: 702
Z
zazang Offline OP
User
zazang  Offline OP
User
Z

Joined: Oct 2003
Posts: 702
Infact its the str_cpy function that is shortening my string.Its really annoying because it was much better in c-script.

I tried to use str_cat to resize it by appending blank spaces but it does not help.

This is the resize code I used :-

var length = str_len(my_str);
length = 175 - length;
blank_str = str_create("#length");
str_cat(my_str,blank_str);


I am trying to resize my_str to 175 characters here,but it does not.

regards
zazang








I like good 'views' because they have no 'strings' attached..
Re: String length [Re: zazang] #200281
04/03/08 11:26
04/03/08 11:26
Joined: Jan 2004
Posts: 2,013
The Netherlands
E
Excessus Offline
Expert
Excessus  Offline
Expert
E

Joined: Jan 2004
Posts: 2,013
The Netherlands
The problem is that blank_str = str_create("#length"); creates a string of only 7 characters long. #, l, e, n, g, t, h = 7. The "#num" syntax only works with string initialization, and only with literals.

You could try:
var length = str_len(my_str);
length = 175 - length;
int i = 0;
for(i = 0; i < length; i++)
{str_cat(my_str, " ");}

Re: String length [Re: Excessus] #200285
04/03/08 12:02
04/03/08 12:02
Joined: Oct 2003
Posts: 702
Z
zazang Offline OP
User
zazang  Offline OP
User
Z

Joined: Oct 2003
Posts: 702
Worked exactly as the master Excessus says..thanks so much !

regards
zazang


I like good 'views' because they have no 'strings' attached..
Re: String length [Re: zazang] #200409
04/03/08 21:50
04/03/08 21:50
Joined: Apr 2005
Posts: 4,506
Germany
F
fogman Offline
Expert
fogman  Offline
Expert
F

Joined: Apr 2005
Posts: 4,506
Germany
while(str_len(szString) < 40){str_cat(szString, " ");}
40 = desired length

I came across the same problem. :-P


no science involved

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