xboxrulz1405241485 0 Report post Posted September 15, 2008 Hey guys,I'm just wondering if there's a CharAt function like there is in Java?I know in Java, you just do this: intArray[0][intCount] = strSIN.charAt(intCount) - '0'; Thanks,xboxrulz Share this post Link to post Share on other sites
faulty.lee 0 Report post Posted September 15, 2008 (edited) Hey guys,I'm just wondering if there's a CharAt function like there is in Java?I know in Java, you just do this: intArray[0][intCount] = strSIN.charAt(intCount) - '0'; Thanks,xboxrulzI'm not sure what type did you declare strSIN as. As far as I know, there's no base string type available in C++ (well, I've not touch C++ for a few years now, maybe something new popup). String normally are represented as char[] or *char or CString. There are other representation, but are less popular. For char[] and *char, it should be easy as it's an array, "CharAt" would simply means char[at] (I forgotten how to do it with *char, but you can lookup in google). As for CString, you need to refer to your class reference, since it could be from ATL, MFC or other lib, they all have different implementation.EDIT: PS: I'm refering to windows here. If you're talking about linux, then CString might not applies Edited September 15, 2008 by faulty.lee (see edit history) Share this post Link to post Share on other sites
magiccode91405241511 0 Report post Posted September 15, 2008 (edited) You may try this to see if it it help for char* int index = 0;char *message = "Hello, Java";char achar = *(message + index);orchar achar2 = message[index]; If I'am not forgot it, there is a class called string on STL.But I'am not good with this class. Edited September 15, 2008 by magiccode9 (see edit history) Share this post Link to post Share on other sites
xboxrulz1405241485 0 Report post Posted September 15, 2008 well, let me clarify that I use the string to store the SIN (Social Insurance Number) and I want to pick out the certain number out to analyze it.Many thanks,xboxrulz Share this post Link to post Share on other sites
magiccode91405241511 0 Report post Posted September 23, 2008 (edited) Sorry, I haven't see this Hi, for c++ string reference. Here have a great web site. [qutoe] http://www.cplusplus.com/reference/string/string/ It should not hard because it looks like java and c# string ----------------------- For quick way because the message pointer variable was 0-based index array So, please change the index variable to point to the char you need. then loop throught it, as, #include "stdio.h"#include "string.h"int main(){ // change the index to start the looping int index = 2; // change this to the number of char required (+ 1 if including null char) int numrequiredchars = 8; // build a simple buffer to hold a new data char *requiredchars = new char[numrequiredchars]; // the source text char *message = "Hello, Java and long long text"; memset(requiredchars, 0, numrequiredchars); for (int i = index; i < numrequiredchars; i++) { *requiredchars = *(message + i); ++requiredchars; } printf("%s\n", requiredchars); //printf("\n%s\n", message);}---For relatively full story I'am not good in explaination but I try my best, char *message = "Hello, Java" means a char pointer variable that is pointing to a memory location in system that start with char H and contain a string Hello, Java Because char *message = "Hello, Java" basically equal char[] = "Hello, Java".So both of it are an char array, except that the formal including a null char at the end of char array ( the string ) And since a char is occupy 1 byte memory, so a pointer address = 1 byte, i.e. 0001 => H0002 => e compared with an integer type that is 4 byte in size, i.e. 0001 => 10005 => 2 That result in, *message = H*(message + 1) = e*(message + 2) = l... If you just print out the message variable with printf,it will show the address that it contains. To get the actually value it pointed to, use the * operator to dereference, as, *message Since not very good in English. So it might be something missed. Wish this help ! Edited September 23, 2008 by magiccode9 (see edit history) Share this post Link to post Share on other sites
xboxrulz1405241485 0 Report post Posted September 24, 2008 Alright, I found an alternative.I'll keep this for reference.Many thanks,Adrien Share this post Link to post Share on other sites