locked
Empty String "" is represented as 0x0000000000000000 L""

    Question

  • When I do:

    auto a = ref new Platform::String(L"");

    The value is 0x0000000000000000 L"", so a == nullptr;

    Does WinRT not allow to represent an empty string? There should be some difference between nullptr and an empty string object.

    Thursday, October 04, 2012 10:41 PM

Answers

All replies

  • Hi,

    I think you are

    	String^ a=nullptr;
    
    	int l=a->Length();
    	if(a==nullptr)
    	{
    		int c=5;
    	}
    	if(a->IsEmpty())
    	{
    		int c=5;
    	}
    

    correct. I test these codes and find that there is no way to make different from nullptr and empty string.

    But, do you have any functional requirements about nullptr string?

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Monday, October 08, 2012 7:47 AM
  • When I do:

    auto a = ref new Platform::String(L"");

    The value is 0x0000000000000000 L"", so a == nullptr;

    Does WinRT not allow to represent an empty string? There should be some difference between nullptr and an empty string object.

    A String is different from a C char string. For

    auto a = ref new Platform::String(L"\0"); 

    The value is also 0x0 but a->Length is 1.

    That may cause confusion in the conversion between C string and RT String. I found sublet bugs in some codes. 


    Charlie Chang L

    Monday, October 08, 2012 4:42 PM
  • Yes.
    But we can use the native c wchar in C++/CX private type.  We can declaration a native C++ class with private type and it will build fine.

    If we want to use this class' value in XAML, we can create a public wrapper.
    A wrapper convert native type to Windows Runtime type.
    We can convert char* to String^ with the codes in this thread
    http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/48794f27-0db7-4335-bdfe-dca664ca28a9

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    • Proposed as answer by Jesse Jiang Thursday, October 11, 2012 7:37 AM
    • Marked as answer by Jesse Jiang Tuesday, October 30, 2012 7:26 AM
    Wednesday, October 10, 2012 6:57 AM