Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (Ayumi), 1,088 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 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 | 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