CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2010
    Posts
    2

    STX \x02 character in code editor?

    Any ideas how to get  to show in VC++ 2010 Express?
    Ive got a few strings that use it to split them, "sometextsometextmaybenumbers242423424etc", but if I paste it into the code editor in VC++, it basically becomes invisible, its still there, you can use the arrow to move past it, but it just takes up no space. So, the text ends up looking like "sometextsometextmaybenumbers234234234".

    Any way to make the  actually show up? In SciTE it comes up with {STX} in place of it, but yeah, nothing in VC++.

  2. #2
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: STX \x02 character in code editor?

    \x02 is not a ascii char, so no, you will not see it in a editor. What you can do is preparse the data yourself and replace the char-code \x02 with actual text '\x02'.
    Last edited by Skizmo; October 29th, 2010 at 07:06 AM.

  3. #3
    Join Date
    Oct 2010
    Posts
    2

    Re: STX \x02 character in code editor?

    Currently ive been doing something like
    Code:
    std::string STX = "\x02";
    
    std::stringstream data;
    data << "sometext" << STX << "sometextetcetc" << STX << "12342342sdfsdf";
    But yeah, when it gets more data in it, it tends to look ugly and confusing to go through.
    Unless you know of a better way, string replace of some sort?

  4. #4
    Join Date
    Feb 2014
    Posts
    1

    Re: STX \x02 character in code editor?

    1. \x02 is the second character in ASCII Characters. It is a Control Characters. It means "start of text". So, it could not be printed.
    2. The UI in Visual Studio 2010 uses WPF, including code editor. The WPF use FontFamily to render its glyph. And if a character's code could not be found in the font you set, the fallback mechanism will be invoked. WPF will assign a default font to substitute. However, the x\02 is not in any Font. So, it will be invisible.
    3. The UI in Visual Studio 2008 uses Font rather than FontFamily. There is no fallback mechanism. So, sometimes you may see a strange character in some font for \x02, like Tahoma Font.
    4. The SciTE is the best practice.

    As a result, you could just paste that character in the code editor. And render it with {STX} in your product.

    Wish it helpful.

  5. #5
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: STX \x02 character in code editor?

    Quote Originally Posted by azkay View Post
    Code:
    data << "sometext" << STX << "sometextetcetc" << STX << "12342342sdfsdf";
    This has the disadvantage that "behind the scenes" results in 5 function calls.
    that may or may not be an issue for your code.

    Code:
    data << "sometext\x02sometextetcetc\x0212342342sdfsdf";
    is only a single function call.

    You could also use C++ literal string catenation (=compile time) and do:

    Code:
    #define STX "\x02"
    data << "sometext" STX "sometextetcetc" STX "12342342sdfsdf";
    which compiles to exactly the same as above.

  6. #6
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: STX \x02 character in code editor?

    Also: enforcing control codes in literal C++ strings (via an editor that supports it, or via hex-editing) may cause "strange effects" in the compilers (depending on the compiler). So even if you can do it in an editor, it's probably still a bad idea.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured