If in a program you have user input from a TextCtrl that you need further on inside a string, there's always the problem of characters that need an escape (\). So my question is: Is there an easy way (function or so) to exclude user input of all characters that need a \ or to automatically replace all these characters with an \ ?
In my specific case... I have text files with product names and other information. The administrator of the program can create new products and thus has to chose product names. This input is then saved in a new text file. The product name is used in the program for the shopping cart. So the product names are read into a string. As these names are read from the text files, all the characters that need a \ have to be written like this into the text file.
Thanks,
Thomas
Exclude all characters that need an escape Topic is solved
-
- Ultimate wxWidgets Guru
- Posts: 670
- Joined: Tue Jul 26, 2016 2:00 pm
Re: Exclude all characters that need an escape
Might be worth a look here if not done so already:
http://docs.wxwidgets.org/3.1/overview_validator.html
http://docs.wxwidgets.org/3.1/classwx_t ... 3d913f24d4
http://docs.wxwidgets.org/3.1/overview_validator.html
http://docs.wxwidgets.org/3.1/classwx_t ... 3d913f24d4
wxWidgets(v3.2.2.1) - Vs2022(v143) - Win10(x64) - DialogBlocks(v5.16.5_Unicode)
-
- Ultimate wxWidgets Guru
- Posts: 670
- Joined: Tue Jul 26, 2016 2:00 pm
Re: Exclude all characters that need an escape
Thanks, didn't know about this functionality. Very helpful!
As I'm not familiar with ASCII and non-ASCII characters... is there an overview of all characters that need an escape \? I mean, I have the option to check the string for alphabetic characters or non-ASCII characters. But I also want the user to be able to use for example / or : and such. So I have to know which ones fall into the category "need a \".
As I'm not familiar with ASCII and non-ASCII characters... is there an overview of all characters that need an escape \? I mean, I have the option to check the string for alphabetic characters or non-ASCII characters. But I also want the user to be able to use for example / or : and such. So I have to know which ones fall into the category "need a \".
Re: Exclude all characters that need an escape
wxWidgets(v3.2.2.1) - Vs2022(v143) - Win10(x64) - DialogBlocks(v5.16.5_Unicode)
-
- Ultimate wxWidgets Guru
- Posts: 670
- Joined: Tue Jul 26, 2016 2:00 pm
Re: Exclude all characters that need an escape
Yes actually in C++.
But the website that you linked doesn't show this "/" character as an escape sequence. But if I want to use this in a string, it won't work. I need it doubled "//".
But the website that you linked doesn't show this "/" character as an escape sequence. But if I want to use this in a string, it won't work. I need it doubled "//".
Re: Exclude all characters that need an escape
I don't know any public method in wxWidgets that does this. There are methods in wxFileConfig, but they're not public.
But i still don't know exactly why you (think you) need this. How do you save the strings into a file and how do you read them back?
But i still don't know exactly why you (think you) need this. How do you save the strings into a file and how do you read them back?
Use the source, Luke!
-
- Ultimate wxWidgets Guru
- Posts: 670
- Joined: Tue Jul 26, 2016 2:00 pm
Re: Exclude all characters that need an escape
Well, for example in the text file it says "Paper/Sheets" without the quotes.
Then in the program I use an ifstream variable to read the text into a string. It just doesn't work if I write "Paper/Sheets", I have to write "Paper//Sheets" to make it work.
EDIT:
After I had written this post it dawned on me. The problem was in the program code and not in the / character. So I can be sure that the characters from the "escape sequences" table from a link above is complete and I only have to exclude these?
Then in the program I use an ifstream variable to read the text into a string. It just doesn't work if I write "Paper/Sheets", I have to write "Paper//Sheets" to make it work.
EDIT:
After I had written this post it dawned on me. The problem was in the program code and not in the / character. So I can be sure that the characters from the "escape sequences" table from a link above is complete and I only have to exclude these?
Re: Exclude all characters that need an escape
As long as your talking about 'escape sequences' a'la the basic c++ standard.Wanderer82 wrote: So I can be sure that the characters from the "escape sequences" table from a link above is complete and I only have to exclude these?
But that table doesn't include the non standard, eg:
Code: Select all
\e = \x1B = escape (non-standard GCC extension)
I did something similar recently and didn't come across your problem, but I used this:Wanderer82 wrote:Well, for example in the text file it says "Paper/Sheets" without the quotes.
Then in the program I use an ifstream variable to read the text into a string. It just doesn't work if I write "Paper/Sheets", I have to write "Paper//Sheets" to make it work.
https://en.cppreference.com/w/cpp/filesystem/path
Last edited by tuk1 on Sat Jun 23, 2018 4:29 pm, edited 1 time in total.
wxWidgets(v3.2.2.1) - Vs2022(v143) - Win10(x64) - DialogBlocks(v5.16.5_Unicode)
Re: Exclude all characters that need an escape
If only string literals in the source code are the problem, the only character you have to escape is "\" itself (not "/").
Use the source, Luke!