IonicWind Software

IWBasic => General Questions => Topic started by: LarryMc on August 17, 2008, 03:17:54 AM

Title: CHAR array to STRING
Post by: LarryMc on August 17, 2008, 03:17:54 AM
I can't remember how to convert a char array to a string.

Larry
Title: Re: CHAR array to STRING
Post by: Ionic Wind Support Team on August 17, 2008, 08:40:09 AM
convert?

A sting is a character array.  Where is the CHAR array coming from.
Title: Re: CHAR array to STRING
Post by: billhsln on August 17, 2008, 11:05:13 AM
My guess:


def ca[250]:char   /* must be < 255 */
def cs:string
def i:int

... code loading ca array

cs = ""
for i=0 to 250
  cs += ca[i]
next i

print cs
end


Probably too simplistic, but should work.

Bill
Title: Re: CHAR array to STRING
Post by: Ionic Wind Support Team on August 17, 2008, 11:08:42 AM
Bill,
If he just wanted to copy the contents of the char array to a string, or memory for that matter, then using a pointer is easiest.


char myarray[1000]
pointer pArray
pArray = myarray

#<string>pArray = somestring
...
somestring = #<string>pArray


I asked him where the CHAR array was coming from, as it is sometimes easier to use an ISTRING, especially when sending UDT references to an API function, since you can access it as a string directly.

Paul.
Title: Re: CHAR array to STRING
Post by: LarryMc on August 17, 2008, 12:40:12 PM
It's coming from the 32 char font name in a LOGFONT return by enumfontfamiliesex.

Before I posted I used the for loop (sort of like Bill suggested) but I tested to see when I hit Chr$(0) because the character array contents could be less than the 32.  Don't know if the test was really required.

I had also tried what Paul said:
where I messed up was usingpArray = myarray[0]instead ofpArray = myarray

but thought there was an easier way.
What I did was create my own logfont UDT and changed the name declaration from
name as char[32] to name as istring[32] and it worked fine.

but I believe Paul's way, as always, is the way to go.

Larry


Title: Re: CHAR array to STRING
Post by: Ionic Wind Support Team on August 17, 2008, 12:50:58 PM
In that case I would use the ISTRING. In fact I have used it ;)