[440] in java-interest

home help back first fref pref prev next nref lref last post

Re: Converting C strings to Java Strings

daemon@ATHENA.MIT.EDU (Jonathan Payne)
Wed Jun 21 23:39:44 1995

Date: Wed, 21 Jun 1995 20:15:47 -0700
From: jpayne@starwave.com (Jonathan Payne)
To: weilerj@std.teradyne.com
Cc: java-interest@java.sun.com
In-Reply-To: <9506220142.AA25345@fudd.std.teradyne.com> (weilerj@std.teradyne.com)

> Date: Wed, 21 Jun 1995 18:42:00 -0700
> From: weilerj@std.teradyne.com (Jason Weiler)
> X-Sun-Charset: US-ASCII
> Sender: owner-java-interest@java.sun.com
> Precedence: bulk
> X-Info: To unsubscribe, send 'unsubscribe' to java-interest-request@java.sun.com
> Content-Type: text
> Content-Length: 638
> 
> I'm trying to convert an array of C-strings to an Array of java strings.
> This whole process needs to be done in C.
> 
> I allocate the needed strings in Java with:
> strs = new String[number];
> I then send this array into the C-code as an ArrayOfString*. 

Actually, I think you send it into C-code as a HArrayOfString *.
Then you unhand it, and can reference the body field, which will be a
HString *.  HString is a typedef of Hjava_lang_String, which is a
java String instance.

So, in your code you say:

	HArrayOfString *Hstrings;

	for (i = 0; i < n; i++) {
		char *str = <some null terminated C string>;

		unhand(Hstrings)->body[i] = makeJavaString(str, strlen(str));
	}
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post