🔒 Locked
Simple string problem.
Advertisement
Original Post
I have a string variable, which contains some sort of text. For instance "Filename.src" I want to insert another string, lets say "Right", before the period in the first string. So the result should be a string containing: "FilenameRight.src" What is the easiest way to do this?
Yes I was referring to in C++.
I was looking for information about the string class in msdn, and I couldnt find anything usefull or the methods you mentioned.
There is just many useless information in msdn and you just cant find what you need unless you already know exactly what you are looking for.
How can I find all the members and methods of the string class in msdn?
I was looking for information about the string class in msdn, and I couldnt find anything usefull or the methods you mentioned.
There is just many useless information in msdn and you just cant find what you need unless you already know exactly what you are looking for.
How can I find all the members and methods of the string class in msdn?
Simple: don't limit yourself to MSDN. The STL has little to do with Microsoft and there is plenty of information available about it outside MSN. To name a few:
C++ Reference
C++ FAQ Lite
Illco
C++ Reference
C++ FAQ Lite
Illco
Here's something to bookmark then:
MSDN: Standard Library Headers
MSDN: std::basic_string Member Functions
In general, typing in std::any_container in MSDN's search will yield you the page(s) that reference it.
EDIT: and yes, looking elsewhere besides MSDN is always a good idea.
MSDN: Standard Library Headers
MSDN: std::basic_string Member Functions
In general, typing in std::any_container in MSDN's search will yield you the page(s) that reference it.
EDIT: and yes, looking elsewhere besides MSDN is always a good idea.
Quote:
Original post by stylin
Here's something to bookmark then:
MSDN: Standard Library Headers
MSDN: std::basic_string Member Functions
In general, typing in std::any_container in MSDN's search will yield you the page(s) that reference it.
EDIT: and yes, looking elsewhere besides MSDN is always a good idea.
Thanks.
I reached myself the pages in the surroundings of basic_string members page, but didnt notice there is a link to the members of basic strings in one of the other pages.
Now I have a problem with those strings.
Thats why I dont like to work with those std libraries, you dont know what is going inside there and its not protected from simple errors.
Here is my code:
The first time I run this method nothing happens, but when I run it in the following line again, I get an error (user breakpoint) in a place with only std methods calls.
If I switch the first call to this method with the second call, I still get the same error in the second call of this method, so it is not dependant in the parameters passed to the method.
Anyone have any idea what I am doing wrong?
Thats why I dont like to work with those std libraries, you dont know what is going inside there and its not protected from simple errors.
Here is my code:
void SpecificFilesCreator::PushDirectionsAnimation (string ResourceName, string FileName, FileListPointer FLPointer){ string ResourceWork, FileWork, InsertString; InsertString = "DownLeft"; ResourceWork = ResourceName; ResourceWork.insert(ResourceWork.length(), InsertString); FileWork = FileName; FileWork.insert(FileWork.find('.'), InsertString); FLPointer.Push(ResourceWork, FileWork); FLPointer.Step(); InsertString = "LeftLeft"; ResourceWork = ResourceName; ResourceWork.insert(ResourceWork.length(), InsertString); // <= FileWork = FileName; FileWork.insert(FileWork.find('.'), InsertString); FLPointer.Push(ResourceWork, FileWork); FLPointer.Step(); InsertString = "UpLeft"; ResourceWork = ResourceName; ResourceWork.insert(ResourceWork.length(), InsertString); FileWork = FileName; FileWork.insert(FileWork.find('.'), InsertString); FLPointer.Push(ResourceWork, FileWork); FLPointer.Step(); InsertString = "RightLeft"; ResourceWork = ResourceName; ResourceWork.insert(ResourceWork.length(), InsertString); FileWork = FileName; FileWork.insert(FileWork.find('.'), InsertString); FLPointer.Push(ResourceWork, FileWork); FLPointer.Step(); InsertString = "DownRight"; ResourceWork = ResourceName; ResourceWork.insert(ResourceWork.length(), InsertString); FileWork = FileName; FileWork.insert(FileWork.find('.'), InsertString); FLPointer.Push(ResourceWork, FileWork); FLPointer.Step(); InsertString = "LeftRight"; ResourceWork = ResourceName; ResourceWork.insert(ResourceWork.length(), InsertString); FileWork = FileName; FileWork.insert(FileWork.find('.'), InsertString); FLPointer.Push(ResourceWork, FileWork); FLPointer.Step(); InsertString = "UpRight"; ResourceWork = ResourceName; ResourceWork.insert(ResourceWork.length(), InsertString); FileWork = FileName; FileWork.insert(FileWork.find('.'), InsertString); FLPointer.Push(ResourceWork, FileWork); FLPointer.Step(); InsertString = "RightRight"; ResourceWork = ResourceName; ResourceWork.insert(ResourceWork.length(), InsertString); FileWork = FileName; FileWork.insert(FileWork.find('.'), InsertString); FLPointer.Push(ResourceWork, FileWork); FLPointer.Step();}The first time I run this method nothing happens, but when I run it in the following line again, I get an error (user breakpoint) in a place with only std methods calls.
If I switch the first call to this method with the second call, I still get the same error in the second call of this method, so it is not dependant in the parameters passed to the method.
Anyone have any idea what I am doing wrong?
If you just want to append a string onto another string, the most intuitive approach would be (which compiles and runs as exected with VC++ Toolkit 2003):
Usually the simplest solution is the best. As for your error, insert() worked just as well for me, so I have no clue.
#include <iostream>#include <string>int main() { std::string resource_name( "Hello" ); std::string insert_string, resource_temp; insert_string = ", world!"; resource_temp = resource_name + insert_string; std::cout << resource_temp << std::endl; insert_string = ", planet!"; resource_temp = resource_name + insert_string; std::cout << resource_temp << std::endl; return 0;}Usually the simplest solution is the best. As for your error, insert() worked just as well for me, so I have no clue.
Quote:
Original post by daerid
Wow... That code is... interesting. Seems like you could benefit from some sort of Data Abstraction.
Do you mean that I didnt insert the repetetive commands into a method?
I dont know why I am actually sometime dont do it.
I guess It is tempting to just mindelessly copy the same code instead of creating a new method.
Keeping the name separate from the extension would help a lot here, as would using some looping.
You could alternatively use the original method signature by first breaking up the filename into its components and then doing the rest as shown.
void SpecificFilesCreator::PushDirectionsAnimation (string ResourceName, string FileName, string FileExt, FileListPointer FLPointer) { string[] firstDirections = { "Down", "Left", "Up", "Right" }; string[] secondDirections = { "Left", "Right" }; for (int i = 0; i < sizeof(firstDirections) / sizeof(string); ++i) { for (int j = 0; j < sizeof(secondDirections) / sizeof(string); ++j) { FLPointer.Push(ResourceName + firstDirections + secondDirections[j], FileName + firstDirections + secondDirections[j] + FileExt); FLPointer.Step(); } }}You could alternatively use the original method signature by first breaking up the filename into its components and then doing the rest as shown.
Ok I have found the problem.
I passed the FLPointer paramter without reference, that caused the problem.
I guess the consipiracy of the standard string is wrong after all, and it is safe to use string. sigh...
Thanks for all the replies.
I passed the FLPointer paramter without reference, that caused the problem.
I guess the consipiracy of the standard string is wrong after all, and it is safe to use string. sigh...
Thanks for all the replies.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement