Convert formatted cstring number to long

Rehab Reda

I need your help Just want to convert a cstring like this one 128,140

to int number 128140

I use this function but it fills number with 128 only.

 _stscanf(text, _T("%d"), &number);

any ideas ?? Thank you :)

AngeloDM

I designed for you this simple function. You can use it as reference code for more complex issue. Following a complete example:

#include <stdio.h>
#include <string>
#include <ctype.h>

using namespace std;

long StingToNumber(string AString)
{
    string LStrNum;
    for(int i=0; i < AString.size(); ++i)
        if( isdigit(AString[i]) )
          LStrNum += AString[i];
    return atoi(LStrNum.c_str());
}

 int _tmain(int argc, _TCHAR* argv[])
{
    string LString = "128,140";

    long LNum = StingToNumber("128,140");

    printf("String %s to number %d", LString.c_str(), LNum);

    return 0;
}

If my solution help you, please remember to check it as answered.

Ciao (from Italy) Angelo

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Convert wide CString to char*

분류에서Dev

How to Convert Oracle Number(19) to Java Long?

분류에서Dev

Convert range formatted as date to text

분류에서Dev

C ++에서 long을 CString으로 변환

분류에서Dev

Convert formatted email (HTML) to plain Text?

분류에서Dev

How to convert list of IDs formatted in varchar into int

분류에서Dev

How can I convert Long[] to IEnumerable<long?>

분류에서Dev

How do I multiply each element in an array with a large number without getting OverflowError: Python int too large to convert to C long?

분류에서Dev

How to store long range number

분류에서Dev

Convert written number to number in R

분류에서Dev

Convert a Bibtex class object to a series of text strings formatted for each citation

분류에서Dev

PHP convert time, day,month and year to a formatted string

분류에서Dev

Convert number to Roman numerals

분류에서Dev

cannot convert boost::lambda::... to long long unsigned int

분류에서Dev

In TCL what is the best way to add 2 very long string formatted hex numbers?

분류에서Dev

How to convert equation from long to Biginteger

분류에서Dev

bc does not completely convert long hexadecimal numbers

분류에서Dev

iOS: calculating the remainder of a division for a long number

분류에서Dev

C ++ Cstring 분할

분류에서Dev

memcpy CString to char *

분류에서Dev

The simplest way to convert a long date format to YY/MM/DD HTML

분류에서Dev

How to convert phonetic phone number to numeric phone number?

분류에서Dev

convert int number to separated number each 3 digits by comma

분류에서Dev

How to convert oracle number type to string with format?

분류에서Dev

How to convert number to width string property? Javascript

분류에서Dev

Convert Text to Number in MySQL to allow arithmetic operators

분류에서Dev

How to convert a positive number to negative in batch?

분류에서Dev

UCHAR * to CString conversion and CString to UCHAR * to conversion in vc++

분류에서Dev

python, rank a list of number/string (convert list elements to ordinal value)

Related 관련 기사

  1. 1

    Convert wide CString to char*

  2. 2

    How to Convert Oracle Number(19) to Java Long?

  3. 3

    Convert range formatted as date to text

  4. 4

    C ++에서 long을 CString으로 변환

  5. 5

    Convert formatted email (HTML) to plain Text?

  6. 6

    How to convert list of IDs formatted in varchar into int

  7. 7

    How can I convert Long[] to IEnumerable<long?>

  8. 8

    How do I multiply each element in an array with a large number without getting OverflowError: Python int too large to convert to C long?

  9. 9

    How to store long range number

  10. 10

    Convert written number to number in R

  11. 11

    Convert a Bibtex class object to a series of text strings formatted for each citation

  12. 12

    PHP convert time, day,month and year to a formatted string

  13. 13

    Convert number to Roman numerals

  14. 14

    cannot convert boost::lambda::... to long long unsigned int

  15. 15

    In TCL what is the best way to add 2 very long string formatted hex numbers?

  16. 16

    How to convert equation from long to Biginteger

  17. 17

    bc does not completely convert long hexadecimal numbers

  18. 18

    iOS: calculating the remainder of a division for a long number

  19. 19

    C ++ Cstring 분할

  20. 20

    memcpy CString to char *

  21. 21

    The simplest way to convert a long date format to YY/MM/DD HTML

  22. 22

    How to convert phonetic phone number to numeric phone number?

  23. 23

    convert int number to separated number each 3 digits by comma

  24. 24

    How to convert oracle number type to string with format?

  25. 25

    How to convert number to width string property? Javascript

  26. 26

    Convert Text to Number in MySQL to allow arithmetic operators

  27. 27

    How to convert a positive number to negative in batch?

  28. 28

    UCHAR * to CString conversion and CString to UCHAR * to conversion in vc++

  29. 29

    python, rank a list of number/string (convert list elements to ordinal value)

뜨겁다태그

보관