Advertising (This ad goes away for registered users. You can Login or Register)

how to compare 2 text strings witch C++?

Programming on your favorite platform, for your favorite platform? Post here
lordscales91
Posts: 76
Joined: Sat Nov 19, 2011 8:19 pm

how to compare 2 text strings witch C++?

Post by lordscales91 » Tue Nov 22, 2011 2:35 pm

Hello everyone, this is my first post here. The thing is that I want to make a "bone translator" that translates the name of the bones of the PMD characters (3D models format that uses a porgram called MMD) from japanese strings to english strings, based on a predefined list.

The input will be a list of bones like this:
上半身



And the output will be a translated list (with the same order):
upper_body
neck
head

My knowledge of C++ is just enough to make a calculator and some simple programs, it means that I am very n00b on programming, so please, help me.
Advertising

wololo
Site Admin
Posts: 3619
Joined: Wed Oct 15, 2008 12:42 am
Location: Japan

Re: how to compare 2 text strings witch C++?

Post by wololo » Tue Nov 22, 2011 3:17 pm

You want to use a dictionary/hash table for your use case.
In C++, you can use the std::map object for that, it's close enough.

Here's the basics:

Code: Select all

//includes
#include <map>
#include <string>
using namespace std;

// definitions.
string jp[] = { "上半身", "首", "頭 " };
string en[] = {"upper_body", "neck", "head"};
size_t count = 3; //number of elements
map<string, string> dictionary;


//Create Dictionary from the arrays above. Ideally you would load that from a file, and get rid of the definitions above
for (size_t i = 0 ; i < count; ++i) {
    dictionary[jp[i]] = en[i];
}

//function to do the translation
string translateIntoEnglish(string jpString) {
    return dictionary[jpString];
} 
That's the basics, this will not compile out of the box, but you should get the idea.

More info:
http://www.cplusplus.com/reference/stl/map/
http://www.cplusplus.com/reference/string/
http://wagic.googlecode.com/svn/trunk/p ... nslate.cpp (the translator we use in Wagic. This will probably not fit your needs, so I suggest to not reuse that directly)
Advertising
If you need US PSN Codes, this technique is what I recommend.

Looking for guest bloggers and news hunters here at wololo.net, PM me!

wololo
Site Admin
Posts: 3619
Joined: Wed Oct 15, 2008 12:42 am
Location: Japan

Re: how to compare 2 text strings witch C++?

Post by wololo » Tue Nov 22, 2011 3:22 pm

To clarify: my code explains how to create your dictionary and how to do a translation for one string. In your use case, you additionally need to load the input list, and do a loop on the translate function to display the output.
If you need US PSN Codes, this technique is what I recommend.

Looking for guest bloggers and news hunters here at wololo.net, PM me!

User avatar
m0skit0
Guru
Posts: 3817
Joined: Mon Sep 27, 2010 6:01 pm

Re: how to compare 2 text strings witch C++?

Post by m0skit0 » Tue Nov 22, 2011 3:36 pm

Wouldn't your question title be "How to translate one string to anotehr in C++" then?
I wanna lots of mov al,0xb
Image
"just not into this RA stuffz"

lordscales91
Posts: 76
Joined: Sat Nov 19, 2011 8:19 pm

Re: how to compare 2 text strings witch C++?

Post by lordscales91 » Tue Nov 22, 2011 3:55 pm

ok, thanks for your replies, but since the program will be without GUI (unless you explain me how to program it XD), the program will run on a command prompt window (sorry, this post should be on the PC programming forum). So, it will be useful that the program can read the input from a txt file and generate a translated one. Also I want that the people who use the program help to improve it, the program will ask the user for translations of unknown strings and will add it to his "database", the database can be a txt with predefined tranlations or something like that.

wololo
Site Admin
Posts: 3619
Joined: Wed Oct 15, 2008 12:42 am
Location: Japan

Re: how to compare 2 text strings witch C++?

Post by wololo » Tue Nov 22, 2011 4:18 pm

Well, I answered your question for strings translations. For the next steps, be creative. I am not coding the entire thing for you :)
If you need US PSN Codes, this technique is what I recommend.

Looking for guest bloggers and news hunters here at wololo.net, PM me!

lordscales91
Posts: 76
Joined: Sat Nov 19, 2011 8:19 pm

Re: how to compare 2 text strings witch C++?

Post by lordscales91 » Tue Nov 22, 2011 4:34 pm

wololo wrote:Well, I answered your question for strings translations. For the next steps, be creative. I am not coding the entire thing for you :)
Have I already mentioned that I am very n00b? Ok, don't give me the entire code, just take my idea and make the program yourself please. It's not necessary to release the source code, but make the program free please... I don't want to learn programming just for make a program, so please. Can you do it for me, please? Or any other who wants do it.

User avatar
codestation
Big Beholder
Posts: 1660
Joined: Wed Jan 19, 2011 3:45 pm
Location: /dev/negi

Re: how to compare 2 text strings witch C++?

Post by codestation » Tue Nov 22, 2011 4:34 pm

lordscales91 wrote:ok, thanks for your replies, but since the program will be without GUI (unless you explain me how to program it XD), the program will run on a command prompt window
CLI rules :geek:
lordscales91 wrote:(sorry, this post should be on the PC programming forum).
Moved it since isn't a PSP project.
lordscales91 wrote: Also I want that the people who use the program help to improve it, the program will ask the user for translations of unknown strings and will add it to his "database", the database can be a txt with predefined tranlations or something like that.
Don't forget to add a [your_favorite_online_source_code_repository] link when you have it working. Seems a interesting project that i will use for sure, i hope that i find enough free time in the near future to work in the MMDAgent engine port again and remove the awkwardness of having japanese names in the PMD read code.

edit:
lordscales91 wrote:Have I already mentioned that I am very n00b? Ok, don't give me the entire code, just take my idea and make the program yourself please. It's not necessary to release the source code, but make the program free please... I don't want to learn programming just for make a program, so please. Can you do it for me, please? Or any other who wants do it.
Please, do not ask for code requests on this subforum
da rules wrote:Do not request people to code something for you.
Also, the issue isn't as trivial as just replace some strings, probably you will need to unfold the whole PMD structure before changing the entity names (at least there are open source implementations that can read PMD files).
Plugin list
Working on: QPSNProxy, QCMA - Open source content manager for the PS Vita
Playing: Error: ENOTIME
Repositories: github, google code
Just feel the code..

lordscales91
Posts: 76
Joined: Sat Nov 19, 2011 8:19 pm

Re: how to compare 2 text strings witch C++?

Post by lordscales91 » Tue Nov 22, 2011 5:43 pm

codestation wrote: Also, the issue isn't as trivial as just replace some strings, probably you will need to unfold the whole PMD structure before changing the entity names (at least there are open source implementations that can read PMD files).
In fact PMD editor has a function to bulk rename the bones, and also can get a list of the bones names, so the thing will be as easy as copy the list from the pmd editor(in japanese strings) and paste to the bone translator, then program will output a translated list that you have to copy back to the pmd editor and rename all the bones just with a click :D If you want to do the program go for it, you don't need to give me any credits, just take my idea and feel free to do what you want.

User avatar
codestation
Big Beholder
Posts: 1660
Joined: Wed Jan 19, 2011 3:45 pm
Location: /dev/negi

Re: how to compare 2 text strings witch C++?

Post by codestation » Tue Nov 22, 2011 6:18 pm

Uh, then just use this PMD editor?
lordscales91 wrote:If you want to do the program go for it, you don't need to give me any credits, just take my idea and feel free to do what you want.
....... nothx :roll:
Plugin list
Working on: QPSNProxy, QCMA - Open source content manager for the PS Vita
Playing: Error: ENOTIME
Repositories: github, google code
Just feel the code..

Post Reply

Return to “Programming”