|
I dont want to replace anything. If I find a \t then I have to execute that \t. Please see the example below.
Execute means, if there is a \t then I have to give 5 spaces (tab).
If there is a \n then I have to move the remaining string to the next line.
I have to process this str:
str = "ABCD\tEFGH\tIJKL\tMNOP\nQRST"
like this:
str = "ABCD(TAB)EFGH(TAB)IJKL(TAB)MNOP(NEWLINE)QRST"
There should be 5 spaces in (TAB)
A newline should be in (NEWLINE)
Thanks,
Josef
|
|
|
|
|
Joseph82 wrote: I dont want to replace anything
Yes, that's what you want to do: you want to replace the string "\t" by a tab character and the string "\n" by a newline character. So you have to replace a sequence "\\t" by a sequence "\t" (that's what you have to specify to the replace function, since you have to escape the "\" character).
Executing a '\t' doesn't mean anything, you can't "execute" a tab or a new line.
|
|
|
|
|
Thanks. But how to do it.
How will I get this output in the CString Variable:
str = "ABCD(5spaces)EFGH(5spaces)IJKL(5spaces)MNOP(newline)QRST"
Thanks
Josef
|
|
|
|
|
Did you check the post from David ? Check the documentation of the function to see how to use it.
|
|
|
|
|
you want to replace the actual "tab" character with the "visual" representation of the tab ?
for example what would happen if the tab is visually represented by 2 spaces or by 3 spaces ?
Watched code never compiles.
|
|
|
|
|
|
so, just replace (CString::Replace) the "\t" with " ".
Watched code never compiles.
|
|
|
|
|
What should I do for newline?
|
|
|
|
|
It make no sense to "execute" a newline inside a string! Inside a string you could put printable characters, like 'a', 'b', 'c' and so on, and/or control characters, like '\t' (i.e. TAB), '\n' (i.e. LF) and so on.
If you pass such a string to functions like printf , that functions will print-out the printable characters and do what the control characters ask for, for example:
printf("first>\tthis is a sentence...\nsecond>\tthis is another sentence...")
will produce an output on screen similar to the following:
first> this is a sentence...
second> this is another sentence...
as you can see TAB (\t) is not simply expanded to a certain number of characters, but it make the text formatted in columns; the LF instead instruct the printf function to move to the beginning of the next line and place the remaining text there.
Then:
- if you like it, you can replace the TABs expanding them to a fixed number of spaces (supposed that you have a
CString named str , you have only to call str.Replace(_T("\t"), _T(" ")); on it); be aware that usually this is not the behaviour of TAB that the rest of the world is expecting. - absolutely it make no sense to replace the \n characters in a string with newline because in strings \n has the meaning of newline!
|
|
|
|
|
|
Hi Friends,
I am presently doing a project in VC++(VS 2008). it having more than 40 dialog's. for that dialogs i'm designing with controls... it is difficult me to maintain the dialogs good and perfect without missing the alignment's...
so please tell me some tips about designing and how to design the dialogs effectively...
Thanks in advance... Rose ...
|
|
|
|
|
|
|
rp_suman wrote: To make sure if the controls are aligned correctly, you can take a snapshot, paste in MS Paint, draw a line, zoom and check the pixels.
If you really like to work, and like spending your customers cash, that may be a good alternative to simply use the alignment tools in the Format | Align sub-menu in the resource editor.
|
|
|
|
|
|
Hi,
I need to update a code that was written a long time ago, and have some problem.
my question is as follow.
I have a Base class with function f1 that do something.
the Derived class ovveride function f1 and do other thing.
now I need to add to the derived class a function f2 that do exactly what Base::f1() is doing.
and I dont want to duplicate the code (of course)
is it OK to do:
void Derived::f2()
{
Base::f1();
}
or is there a better way to call the f1 from the base class?
Many thanks,
|
|
|
|
|
lune12 wrote: Base::f1();
That's how you should do it.
|
|
|
|
|
You don't actually have to implement a function to call a base class version of a function:
Derived d;
d.base::f();
will call the base class version of f - no virtual function dispatch will happen.
Oh, don't try this the other way around - strange and destructive things will happen
Cheers,
Ash
|
|
|
|
|
Actually there are scenarios where this is useful, like exposing methods from private and protected inheritance. A sort of forwarding.
class Base
{
public:
string name() const;
};
class Derived : protected Base
{
public:
string name() const { return Base::name(); }
};
Edit: The reason being of course to change the access level of a method.
|
|
|
|
|
Just a thought: As someone who prefers composition over inheritance, I can hardly think of a case using protected/private inheritance. Not sure when I used it last time. Also see Stackoverflow[^].
Cheers
/Moak
|
|
|
|
|
It's more likely to be used to open up a protected function in the base class. I've seen that a lot in MFC code and it gives me the willies:
class base
{
protected:
virtual void a();
};
class derived : public base
{
public:
virtual void b()
{
a();
}
};
You can also do it using using declarations but that's scary as well.
Cheers,
Ash
|
|
|
|
|
Begs for a redesign/refactoring of the interface, if you ask me.
|
|
|
|
|
I have actually never inherited in any other way than public as far as I can recall, but elevating the access level of a function does not need protected or private inheritance though.
|
|
|
|
|
In this case I'd almost certainly rewrite the base class to provide what I want than hack the derived class. I know there are social reasons why it may be preferable to forward calls like that but it leaves a bad taste in my mouth.
Actually the real bad taste is implementation inheritance but in the world of GUI frameworks people are very stuck in the early 90s.
Cheers,
Ash
|
|
|
|
|
Unfortunately, far from all classes can be rewritten (for several reasons other than social)
I have used this for access level elevation a couple of times (probably more than two) in about 17 years, so it's not really common, but I believe there is a use for it.
There are of course also other reasons to implement a method in terms of the base class implementation. Code generation tools does it all the time. Mostly along with ToDo comments.
|
|
|
|