[Mono-bugs] [Bug 565703] UITextField.get_Text has problems with encoding
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Mon Dec 28 00:58:18 EST 2009
http://bugzilla.novell.com/show_bug.cgi?id=565703
http://bugzilla.novell.com/show_bug.cgi?id=565703#c5
--- Comment #5 from Ed Anuff <ed at anuff.com> 2009-12-28 05:58:16 UTC ---
Sorry for the bad information, the problem doesn't appear to be in
System.String, but probably in NSString.ToString().
In any case, the following code does return the correct Unicode string:
[DllImport (MonoTouch.Constants.ObjectiveCLibrary, EntryPoint="objc_msgSend")]
public static extern void void_objc_msgSend_IntPtr_NSRange (IntPtr receiver,
IntPtr selector, IntPtr arg1, MonoTouch.Foundation.NSRange arg2);
public static string GetText(UITextField ob) {
NSString nsstr = new NSString(Messaging.IntPtr_objc_msgSend(ob.Handle, new
Selector("text").Handle));
int len = (int)Messaging.UInt32_objc_msgSend(nsstr.Handle, new
Selector("length").Handle);
IntPtr data = Marshal.AllocHGlobal(len * 2);
NSRange range = new NSRange();
range.Length = len;
range.Location = 0;
void_objc_msgSend_IntPtr_NSRange(nsstr.Handle, new
Selector("getCharacters:range:").Handle, data, range);
char[] strData = new char[len];
Marshal.Copy(data, strData, 0, len);
string str = new String(strData);
Marshal.FreeHGlobal(data);
return str;
}
--
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.
More information about the mono-bugs
mailing list