Unreadable characters

Is there a standard way to convert a string with unreadable characters to an “Oxygene” string like
‘Here comea an #13#10 unreadble #0 character #9

1 Like

Not currently, but this is a good idea. What’s the best way you’d like to see this exposed, something like “Edit|Paste as Escaped String” which would generate a string literal from the clipboard contents, or a context menu that would convert a current selection within a string to an escaped version?

Note that this would in all likelihood be something I’d implement for Fire/Water, as it’d be a quick thing to do there, while adding anything to Visual Studio takes weeks (and the VS team is millions of more important issues behind for adding frivolous stuff like this. One of the reasons we’re pushing more and. ore for Fire/Water as the main IDEs.)

No, more as an extension method on string; I need it for logging - my test failed on a field with #0 in it.

Oh. No I don’t believe there is. I’ll see if/how this would make sense adding to Elements RTL…

I don’t think there will be much people using it I think, so don’t spend your time on it.
The question was only to prevent me from building something that is already there.

That said, I did just ass this one:

for Fire/Water, (won’t make it into today’s build).

If you want some code to nick or implementing you’re own, look at CodeGen4’s lightly mis-named AppendPascalEscapeCharactersInStringLiteral method. Not that it’s rocket science ;).

Already have it (found it on code project and change CSHARP wit Oxygene):

using writer := new System.IO.StringWriter do
begin
    using provider := System.CodeDom.Compiler.CodeDomProvider.CreateProvider("Oxygene") do
    begin
        provider.GenerateCodeFromExpression(new System.CodeDom.CodePrimitiveExpression(self), writer, nil);
        exit writer.ToString();
    end;
end;

That’ll work, but only on systems that have Oxygene installed :wink:

Good point.
Then I use the CSharp version - that is always installed.

Making it:

using writer := new System.IO.StringWriter do
begin
    using provider := System.CodeDom.Compiler.CodeDomProvider.CreateProvider("CSharp") do
    begin
        provider.GenerateCodeFromExpression(new System.CodeDom.CodePrimitiveExpression(self), writer, nil);
        exit writer.ToString();
    end;
end;