|
LPTSTR is basically a "char *" in ANSI/MBCS mode and "wchar_t *" in UNICODE mode.
My code is basically exactly the same thing remove_if does. At the end of my loop, "pszOut" would be the same as your "i". My terminating the string with a 0 does what your erase does.
Mine is for C style strings and yours is for STL strings. Since your version doesn't do a lot of extra string copies they both perform very well. The only thing in the C string version is that you could roll the tolower into the loop.
This STL version looks good IMHO.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Just for an FYI, here is how your routine would look for C strings.
void CleanUpWord (char *pszWord)
{
char *pszIn = pszWord;
char *pszOut = pszWord;
char c;
while ((c = *pszIn++) != 0)
{
if (!ispunct (c))
*pszOut++ = tolower (c);
}
*pszOut++;
}
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Sorry,I misunderstood your question,you have to use Remove() .This is from MSDN:
CString str("This is a test.");
int n = str.Remove('t');
ASSERT(n == 2);
ASSERT(str == "This is a es.");
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
CString strTest("What the *@(%!?");
CString Holder = "-?`~!@#$%";
for (int i = 0; i < strTest.GetSize(); i++)
if(Holder.Find(strTest.GetAt(i))!=-1))
{
AfxMessageBox("Found bad character");
}
:P im a newbie so flame away if there is an easier way.. oh ya.. i stole this code from someone somewhere at somepoint..
-dz
|
|
|
|
|
If you're using std::string s, this should do (warning, I haven't tested it so some off-by-one errors might have been overlooked.)
string remove(const string& src,const string& chars)
{
string dst;
for(string::size_type off=0,off2=0;(off=src.find_first_of(chars,off2))!=string::npos; ){
off2=src.find_first_not_of(src,off);
dst+=src.substr(off,off2==string::npos?string::npos:off2-off);
}
return dst;
}
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Arg.. can someone tell me the best choice for a grid? i see all these fancy grids in the articles which have pictures and stuff.. but all i want is a grid which lists rows of items with 3 or 4 columns from which i can figure out what line is selected, and set whether you can have multiple selections or not.. basicly i just need a listbox almost, except i want columns.. any suggestions? im trying to use the MSFlexGrid, but i'm having problems putting them into .NET (see previous post from today).
thanks for any suggestions
-dz
|
|
|
|
|
|
CListCtrl is pretty easy, not to fancy, supports multiple selections (i think) and columns.
Perhaps this is what your looking for.
Cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
wow, i really apreciate you pointing that out.. i was wondering why all these grid controls were so fancy.. i dont need an editable grid, just a listing.. didn't know list box allowed columns when its in 'report' mode.. thanks for the help!
-dz
|
|
|
|
|
Hi,
Is it possible to have dynamic array in VC++??? I mean....can i have the following code:
cout << "Input array size ";
cin >> size;
int arrayvalue[size];
Thanks!
|
|
|
|
|
No, that is because creating an array with int arrayvalue[size] allocates space for your array on the stack, and that requires the compiler to know how large the buffer is. Which means that size cannot be a dynamic value.
In order to dynamically allocate space for the array, you will need to allocate space with a pointer like this:
cin >> size;
int *arrayvalue = new int[size];
if (NULL == arrayvalue)
{
}
else
{
arrayvalue[0] = 100;
...
delete[] arrayvalue;
}
One more thing, you should make sure that the value for array is not 0, because you will get a valid pointer back for an array of size zero, but if you try to access the array at all, you will be an memory access violation.
|
|
|
|
|
Yes, you can achieve this using many approaches. The easiest is to use Standard C++ library and its vector class:
#include <vector>
std::vector<int> v;
int size;
cin >> size;
v.resize(size);
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Not the way you wrote this. Actually, by C99 standard this is possible, but VC does not support it (yet?).
Instead, you can use std::vector, which is much more flexible and easy to use. Or you can write
int* arrayvalue = new int[size];
and call
delete[] arrayvalue;
when you finish. However, I suggest vector.
I vote pro drink
|
|
|
|
|
im a newbie myself, but i have been using CStringArray, CObArray, and CUIntArray. These are build in classes for arrays of different types. They are cool because you can add and delete them without caring about what the size is. example:
// add stuff to it
CStringArray strArray;
CString strTemp("Hello");
strArray.Add(strTemp);
strTemp = "Second string";
strArray.Add(strTemp);
// get stuff from it
strTemp = strArray.GetAt(0);
strTemp += strArray.GetAt(1);
// delete an unwanted string
CString* pStr = strArray.GetAt(0);
delete pStr;
strArray.Remove(0);
keep in mind that these are arrays of pointers which point to strings, or objects, etc.
-dz
|
|
|
|
|
Might I recommend that you look into the stl:vector as recommended above ? Much better than lousy MFC container classes, which were only ever a stopgap while the STL was on it's way.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm thinking of getting married for companionship and so I have someone to cook and clean." - Martin Marvinski, 6/3/2002
|
|
|
|
|
Hi,
Does anyone know how to create a global variable so that all classes in the project can share.
For example, i need this global variable:
int temp;
No matter which class I'm currently, i just use it as normal:
temp = temp + 1; (nothing liked.......... XXXX.temp = XXXX.temp + 1
I know I need to create a file to store all those global variable...but i forgot how to do it.
Anyone can help?????
|
|
|
|
|
Declare teh variable in a header and include that header in all clases, or declare that variable in the App class and you can get the class using AfxGetApp() for get a pointer to CWinApp class
best Regards
Carlos Antollini.
Sonork ID 100.10529 cantollini
|
|
|
|
|
If you are not using MFC, then declare the variable in stdafx.cpp like you want it.
This block has been added to the original message to clarify some confusion.
My response was after Carlos' which was a response for MFC, his response was on the thread before this one. I added the statement about MFC just in to clarify that if the person who posted the question was not using MFC and could not use the CWinApp object. The technique that I posted will work for any type of C++ project.
int g_Temp;
Then you will need to declare it in stdafx.h like this:
extern int g_Temp;
The extern tells each file that it is included in to add the g_Temp variable to the symbol table so that the variable can be used, but does not actually allocate space for that variable in the obj file. Then when the linker comes around it will resolve all of the variable locations and what not.
If you do not use the extern keyword, and you declare the variable in the header, then your program will allocate space for each file that the variable was declared in, and when the linker tries to resolve all of the variable addresses, it will find collisions.
|
|
|
|
|
|
Well you beat me to the MFC solution, so we'll call it even .
|
|
|
|
|
kilowatt wrote:
If you are not using MFC,
What does MFC have to do with it ? I do this in MFC apps all the time.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm thinking of getting married for companionship and so I have someone to cook and clean." - Martin Marvinski, 6/3/2002
|
|
|
|
|
Christian Graus wrote:
What does MFC have to do with it ? I do this in MFC apps all the time.
I simply added this just in case the person who posted the question was not using MFC and did not have access to the CWinApp class inside of their program.
Tomasz Carlos Antollini post on the thread before this thread stated this:
Declare teh variable in a header and include that header in all clases, or declare that variable in the App class and you can get the class using AfxGetApp() for get a pointer to CWinApp class
Of course this method that I mentioned is possible in both an MFC and non-MFC apps alike.
|
|
|
|
|
kilowatt wrote:
Tomasz post on the thread before this thread stated this:
Declare teh variable in a header and include that header in all clases, or declare that variable in the App class and you can get the class using AfxGetApp() for get a pointer to CWinApp class
It was Carlos' post, actually.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I see - that you were replying to a previous reply was not clear to me.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm thinking of getting married for companionship and so I have someone to cook and clean." - Martin Marvinski, 6/3/2002
|
|
|
|
|
This technique will work on any type of project that has the two files named. It does not have anything to do with MFC. If you don't have files by that name, put the extern in every module where you reference the global. Put the definition in any .cpp file in your project.
,
Bill
|
|
|
|