[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



--- 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

    int len = (int)Messaging.UInt32_objc_msgSend(nsstr.Handle, new
    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);


    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