Compare String in String

Hello

I need a help.

I have two different numbers... I know that some part of them, are equal.
Eg: after 4th digit, they are equal... (phone number without prefix)

Which is the best way to compare them?

Thanks on advance
Pedro Ferrer

What do you mean by "compare"? Do you want to know if any part of them are the same?

Are they actual numbers or strings, where each character is between '0' and '9'?

All I can suggest without further information is to look into the modulo operator (%) and use it with integer division.

All I can suggest without further information is to look into the modulo operator (%) and use it with integer division.

Well, perhaps the String::substring() function might be employed, to extract the parts of the Strings of interest, which can then be compared. Presuming you are talking about String objects containing phone numbers...

If you get off the C++ String objects, you can avoid future Arduino sketch memory problems.

From AVR-LibC string.h (as in C string arrays) library:

char * strstr ( const char * s1, const char * s2 )

Locate a substring.

The strstr() function finds the first occurrence of the substring s2 in the string s1. The terminating '\0' characters are not compared.

Returns:
The strstr() function returns a pointer to the beginning of the substring, or NULL if the substring is not found. If s2 points to a string of zero length, the function returns s1.

http://www.nongnu.org/avr-libc/user-manual/group__avr__string.html

http://www.nongnu.org/avr-libc/user-manual/modules.html

Hello

For one side I have an int array with the number... for other side I'll have a string, I suppose ...
Following the String step by step, I can compare with the int array...

It seems to me that I'm complicating the things... since I'll have many conversions...

comparison1 "123456789"
comparison2 "+315123456789"

Please let me know
Pedro Ferrer

Find the length of the shorter number. Index in the length of the longer number minus the length of the shorter number. Do a memcmp.

You suppose? Don't you know?

You may have to convert the int to a string.

comparison1 "123456789"

That won't fit into an int.

Hello

Thanks Nick

One of the problems is that I don't ensure the fixed part...
Can be '+351'... or '+34'... or '+39'...
Portugal, Italy, Spain... whatever...
Perhaps it's better to convert the int array as String... than compare both strings... using 'substring'...

Pedro Ferrer

Probably better to convert strings to ints, depending on which you have most and what the data must end up as.

Running on text is like running with concrete boots.