April 29, 2024, 12:06:27 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


CHAR array to STRING

Started by LarryMc, August 17, 2008, 03:17:54 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

LarryMc

I can't remember how to convert a char array to a string.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ionic Wind Support Team

convert?

A sting is a character array.  Where is the CHAR array coming from.
Ionic Wind Support Team

billhsln

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
When all else fails, get a bigger hammer.

Ionic Wind Support Team

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.
Ionic Wind Support Team

LarryMc

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


LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ionic Wind Support Team

In that case I would use the ISTRING. In fact I have used it ;)

Ionic Wind Support Team