I am receiving the contact list from device, now I want to remove country codes from numbers maybe one number will be have the country code with +1 or 01
How can I do it , I want to remove country codes from all numbers any country
Here's what I would do. There are plenty of resources online that has a list of country codes. I'll download them and compare them with each number in the contact list. And finally run whatever removal operation I have.
Edit: Before running the above algorithm, I would first clean the data.
Remove all whitespaces.
Replace the leading 0 with + or vice versa depending on the available dataset
you can store them in a vector and when you retrieve the information you can skip the first elements which belongs to the country code. usually telephone numbers have 9 numbers besides country code. you can fix the output array indexes.
only way to remove the country code from the phone number is after making sure to which country the phone number belongs to.
if you are sure about +1 or 01 or any first two digit is the country code,
number.substring(2);
will give you the number.
if this is still relevant.
since all numbers are 10 characters you can do
number.substring(number.length - 10)
this would take the last 10 digits regardless of the country code with plus or not
aah hey, this question was asked earlier but anyways will answer it ..
THE FOLLOWING CODE IS WRITTEN IN JAVA
there are 2 ways to solve this !
1st
String abc="+91 9000000009";
abc=abc.replaceAll(" ","");
int count=0;String Num="";
for(int i=abc.length()-1;i>=0;i--)
{
if(count<10)//change number 10 according to the preferred number of digits of Phone Number Excluding country code
{
Num=abc.charAt(i)+Num;
count++;
}
else
{
break;
}
}
System.out.println("Number Without Country Code : "+Num);
2nd
String abc="+91 9000000009";
abc=abc.replaceAll(" ","");
String Num1=abc.substring(abc.length()-10);//change number 10 according to the preferred number of digits of Phone Number Excluding country code
System.out.println("Number Without Country Code : "+Num1);
Both The Ways Work Fine
but in the second way if then is less than '10' then it would cause a error !
Related
I created a function (using flutter_contacts) that searches contacts on my Phone based on a given contact cell number (input - cellnumber) :
Contact? contact = contacts.firstWhereOrNull((c) => c.phones.contains(Phone(cellnumber)));
It works completely ok when I search for a number without "+" sign (e.g. 12345) and the contact in the contact list has a number without "+" (e.g. 12345).
But it doesn't work when I search for a number with "+" sign (e.g. +12345) and the contact has a number with plus (e.g. +12345).
Anyone knows why is that and how to fix it?
If you look at the code you will see that for the Phone class to be equal to another, there needs to be more components to match than just the phone number.
So to check for phone numbers only, you need to roll your own coparison:
Contact? contact = contacts.firstWhereOrNull((c) => c.phones.any((phone) => phone.number == cellNumber);
If this still does not match, print all the contacts to debug it. I have no idea what your contact list contains or why it would not match.
There is a normalizedNumber property, maybe you need to use that instead to figure out if someone used formatting like "+1 (234) 567-8900".
I'm new to ASP & Clingo and I need to work on a project for school. I thought about some basic music generator.
For now, I need to generate notes (I'm sticking with C major for now). I also want to generate them randomly and I don't know how to do that. How can I make the following code generate a random sequence of notes (duplicates too)?
note(c;d;e;f;g;a;b).
20 { play(X) : note(X)} 30.
#show play/1.
So far, the code won't allow for more than 7 as the upper bound, because it won't show duplicate notes.
Current output: play(b) play(g) play(e) play(c)
Wanted output: play(d) play(g) play(f) ...[20-30 randomly generated notes]
I want to be able to add constraints later (such as this note should not be followed by that note, and so on). I appreciate any tips since I know so little about this.
An answer set is a set. The atoms have no order and duplicates are not possible because it is a set.
You want to guess one note for each beat.
beat(1..8).
1 { play(N,B) : note(N) } 1 :- beat(B).
Hi all – I need some assistance with prefixing leading zeros into a string.
I have had a look around in the forum but did not quite find anything that suits my scenario.
The string in the column is in the following format: ‘INV-ACC-180 Some description etc’
The ‘INV-ACC-180’ bit is always the same format whilst the description can vary.
The challenge is the ‘180’. Its needs to be 4 leading zeros so it shows as 0180. i.e ‘INV-ACC-0180 Some description etc’
Some records may look like ‘INV-ACC-80 Some description etc’. And in this case the new correct format should be ‘INV-ACC-0080 Some description etc’
Many thanks in advance!
Is the 180 stored as a separate value ?
In that case you create 0180 using:
RIGHT('0000' + mynum, 4)
if the complete string is the input:
‘INV-ACC-' + RIGHT('0000'+substring(myinput,9,charindex(' ',myinput)-9),4) +substring(myinput,charindex(' '),1000)
Hello everyone I am trying to get prefix of phone numbers in order to get the actual phone number without country dialing code. How can I achieve this?
Please note that the phone numbers can be
123456789
0099123456789
+9912345678
or any other formats with country code and area code etc..
if you tried like this then it will help some what but not sure ,
NSString *str=[PhoneNumber substringToIndex:[PhoneNumber length]-10];
Taking a look at the amount of different prefixes you can have List of country calling codes [wikipedia] and Internatioal dialing prefix [wikipedia], one could reach the conclusion that without narrowing the area down you'll probably not get very far with this.
If however you'll be handling phone numbers from a specific region to another specific region you might be able to come up with something.
I'm making a code generation script for UN/LOCODE system and the database has unique 3 letter/number codes in every country. So for example the database contains "EE TLL", EE being the country (Estonia) and TLL the unique code inside Estonia, "AR TLL" can also exist (the country code and the 3 letter/number code are stored separately). Codes are in capital letters.
The database is fairly big and already contains a huge number of locations, the user has also the possibility of entering the 3 letter/number him/herself (which will be checked against the database before submission automatically).
Finally neither 0 or 1 may be used (possible confusion with O and I).
What I'm searching for is the most efficient way to pick the next available code when none is provided.
What I've came up with:
I'd check with AAA till 999, but then for each code it would require a new query (slow?).
I could store all the 40000 possibilities in an array and subtract all the used codes that are already in the database... but that uses too much memory IMO (not sure what I'm talking about here actually, maybe 40000 isn't such a big number).
Generate a random code and hope it doesn't exist yet and see if it does, if it does start over again. That's just risk taking.
Is there some magic MySQL query/PHP script that can get me the next available code?
I will go with number 2, it is simple and 40000 is not a big number.
To make it more efficient, you can store a number representing each 3-letter code. The conversion should be trivial because you have a total of 34 (A-Z, 2-9) letters.
I would for option 1 (i.e. do a sequential search), adding a table that gives the last assigned code per country (i.e. such that AAA..code are all assigned already). When assigning a new code through sequential scan, that table gets updated; for user-assigned codes, it remains unmodified.
If you don't want to issue repeated queries, you can also write this scan as a stored routine.
To simplify iteration, it might be better to treat the three-letter codes as numbers (as Shawn Hsiao suggests), i.e. give a meaning to A-Z = 0..25, and 2..9 = 26..33. Then, XYZ is the number X*34^2+Y*34+Z == 23*1156+24*34+25 == 27429. This should be doable using standard MySQL functions, in particular using CONV.
I went with the 2nd option. I was also able to make a script that will try to match as close as possible the country name, for example for Tartu it will try to match T** then TA* and if possible TAR, if not it will try TAT as T is the next letter after R in Tartu.
The code is quite extensive, I'll just post the part that takes the first possible code:
$allowed = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ23456789';
$length = strlen($allowed);
$codes = array();
// store all possibilities in a huge array
for($i=0;$i<$length;$i++)
for($j=0;$j<$length;$j++)
for($k=0;$k<$length;$k++)
$codes[] = substr($allowed, $i, 1).substr($allowed, $j, 1).substr($allowed, $k, 1);
$used = array();
$query = mysql_query("SELECT code FROM location WHERE country = '$country'");
while ($result = mysql_fetch_array($query))
$used[] = $result['code'];
$remaining = array_diff($codes, $used);
$code = $remaining[0];
Thanks for your opinion, this will be the key to transport codes all over the world :)