In my application I need to get the SIM card number. I am getting that with SIMCardInfo.getIMSI(), but in some other format.
My SIM number is 89919400002018929130, but I am getting: 404940.20.189291.3
I used the following code:
try
{
currentSimNo = GPRSInfo.imeiToString(SIMCardInfo.getIMSI());
}
catch (Exception e)
{
}
The imeiToString takes a IMEI not a IMSI
sampath says:
My SIM number is 89919400002018929130, but I am getting: 404940.20.189291.3
If I line up your two numbers and remove separators, it does look like they are roughly the same:
89919400002018929130
404940201892913
Where did you get the first one from?
In the Wikipedia article on IMSI, you can see that the first three digits are the MCC, then the second three are the MNC. So it looks like your SIM is from India, though I don't see a MNC that matches 940.
These values are frequently encoded as binary-coded decimal, which is why the imeiToString method needs to be used.
EDIT
The IMSI wikipedia article also mentions:
An IMSI is usually presented as a 15 digit long number, but can be shorter.
I think your code is returning the correct value as 404940201892913. Whatever number you are trying to compare it to (899194...) must be encoded differently.
Related
I have been looking around and have read a lot of different answers but none seems to answer my specific request.
I make watchfaces for Wear OS 2 with an app called ''WATCHMAKER'' witch uses LUA as language. I want to make a watch face with a special clock pointing to a number depending on a blood sugar value sent by an transmitter connected to the body.
The string values I want to parse follows this syntax:
<DECIMAL NUMBER> <ARROW> (<TIME>)
One example would be
5,6 -> (1m)
I want to extract the <DECIMAL NUMBER> part of the reading. In the above example, I want the value 5,6.
Every 5 minutes, the transmitter sends another reading, all of those informations change:
5,8 - (30 secondes)
Thank you so much
Say you have a string, in LUA, s="14,11 -> (something)" and you want this first number of the string to be parsed to a float so you can do maths on it.
s='9,6 -> (24m)'
-- Now we use so called regular expressions
-- to parse the string
new_s=string.match(s, '[0-9]+,[0-9]+')
-- news now has the number 9,6. Which is now parsed
-- however it's still a string and to be able to treat
-- it like a number, we have to do more:
-- But we have to switch the comma for a period
new_s=new_s:gsub(",",".")
-- Now s has "9.6" as string
-- now we convert it to a number
number = string.format('%.10g', tonumber(new_s))
print(number)
Now number contains the number 9.6.
Trying to work out how to parse out phone numbers that are left in a string.
e.g.
"Hi Han, this is Chewie, Could you give me a call on 02031234567"
"Hi Han, this is Chewie, Could you give me a call on +442031234567"
"Hi Han, this is Chewie, Could you give me a call on +44 (0) 203 123 4567"
"Hi Han, this is Chewie, Could you give me a call on 0207-123-4567"
"Hi Han, this is Chewie, Could you give me a call on 02031234567 OR +44207-1234567"
And be able to consistently replace any one of them with some other item (e.g. some text, or a link).
Am assuming it's a regex type approach (I'm already doing something similar with email which works well).
I've got to
text.scan(/([^A-Z|^"]{6,})/i)
Which leaves me a leading space I can't work out how to drop (would appreciate the help there).
Is there a standard way of doing this that people use?
It also drops things into arrays, which isn't particularly helpful
i.e. if there were multiple numbers.
[["02031234567"]["+44207-1234567"]]
as opposed to
["02031234567","+44207-1234567"]
Adding in the third use-case with spaces is difficult. I think the only way to successfully meet that acceptance criteria would be to chain a #gsub call on to your #scan.
Thus:
text.gsub(/\s+/, "").scan(/([^A-Z|^"|^\s]{6,})/i)
The following code will extract all the numbers for you:
text.scan(/(?<=[ ])[\d \-+()]+$|(?<=[ ])[\d \-+()]+(?=[ ]\w)/)
For the examples you supplied this results in:
["02031234567"]
["+442031234567"]
["+44 (0) 203 123 4567"]
["0207-123-4567"]
["02031234567", "+44207-1234567"]
To understand this regex, what we are matching is:
[\d \-+()]+ which is a sequence of one or more digits, spaces, minus, plus, opening or closing brackets (in any order - NB regex is greedy by default, so it will match as many of these characters next to each other as possible)
that must be preceded by a space (?<=[ ]) - NB the space in the positive look-behind is not captured, and therefore this makes sure that there are no leading spaces in the results
and is either at the end of the string $, or | is followed by a space then a word character (?=[ ]\w) (NB this lookahead is not captured)
This pattern will get rid of the space but not match your third case with spaces:
/([^A-Z|^"|^\s]{6,})/i
This is what I came to in the end in case it helps somebody
numbers = text.scan(/([^A-Z|^"]{6,})/i).collect{|x| x[0].strip }
That gives me an array of
["+442031234567", "02031234567"]
I'm sure there is a more elegant way of doing this and possibly you'd want to check the numbers for likelihood of being phonelike - e.g. using the brilliant Phony gem.
numbers = text.scan(/([^A-Z|^"]{6,})/i).collect{|x| x[0].strip }
real_numbers = numbers.keep_if{|n| Phony.plausible? PhonyRails.normalize_number(n, default_country_code: "GB")}
Which should help exclude serial numbers or the like from being identified as numbers. You'll obviously want to change the country code to something relevant for you.
Here's what I've tried so far. Is there something wrong with my Regex?
^(?:|0|[1-9]\\d*)(?:\\.\\d*)?.{10}$
What i did was values must be numbers only and with a maximum number of 10. I have no idea what my code doesn't catch when I input more than 10 numbers.
You can use following REGEX
/^(\+\d{1,3}[- ]?)?\d{10}$/
For more information use following links:
http://www.regular-expressions.info/numericranges.html
http://www.regexr.com/
You want only numeric values from 1 to maximum 10 so this is the REGEX for that:
[0-9]{1,10}
If this is not what you need then let us know a little bit more.
You can use https://www.regex101.com to test your REGEX
Use this regex, it also supports country code and spacing: /^(\+\d{1,3}[- ]?)?\d{10}$/
Do you want to have a maximum of 10 numbers only?
The below regex works for 8-10 digits in the number
if ($phone =~ /^[0-9]{8,10}$/) {
print "this is a valid phone number\n";
} else {
print "not a valid phone number \n";
}
I have a Cisco ASA 8.4 VPN Concentrator. I am trying to use Lua to extract digits from a certificate string coming in and use them in a LDAP lookup with AD for authorization. I found a string that works...sometimes.
The string comes in with the format:
LAST_NAME.FIRST_NAME.MIDDLE_NAME.1234567890
My LDAP only wants to see the digits and #domainname. The script I am currently us is: return string.gsub(cert.subject.cn, "^(%w+)%.(%w+)%.(%w+)%.(%w+)$", "%4#domain")
This script works fine in most cases (80-90% of the time). When it doesn't work is when people have no middle name, 4 names instead of 3, etc.
My question is how can I get it to output only the 10 digits, regardless of what comes before it. Seems too easy with a return string.match, but so far I can't get it to work. Any ideas?
You can use the pattern .*(%d%d%d%d%d%d%d%d%d%d)$:
local str = 'LAST_NAME.FIRST_NAME.MIDDLE_NAME.1234567890'
print(str:match('.*(' .. ('%d'):rep(10) .. ')$'))
or .*(%d+)$ if the number of digits is always 10.
If the 10 digits is always the last 10 characters, this works:
print(str:sub(-10, -1))
When performing calculations on large numbers, how does one properly output the result in the right String format for the end user to see? I've tried the different format specifiers for NSString and compared the results to what the iOS Calculator app shows and some of the results aren't the same. Ideally it would match the iOS Calculator results exactly.
I know it needs to be displayed in decimal format until the number is sufficiently large, and at that point it needs to be shown in scientific notation. Therefore I thought %g was the right specifier. But it doesn't match the built-in calculator for the same calculation.
[NSString stringWithFormat:#"%g", calcResult] //where calcResult is a double
Some examples:
123456.7 * 1 should display as 123456.7 but it is displayed as 123457 (puzzling!)
123456789 * 1 should display as 123456789 but it's displayed as 1.23457e+08
123456789 * 123456789 should display as 1.524158e+16 but it's displayed as 1.52416e+16
Also, how does one get the comma (or period depending on locale) to appear in the result? Are there additional specifiers one can use to get the exact format the iOS Calculator shows?