How to ignore unnecessary input of Zeros (0) and dot (.) in a calculator app using kotlin/android studio [closed] - string

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 days ago.
Improve this question
1--> Ive been trying to make a calculator app. My problem is that I want my app to ignore unnecessary repeating input by the user to avoid having this kind of repeating zeros(0) and dot(.) : 00000.003, 3..03, 3+00000.003, etc
I'm new here so I don't know what else I could experiment on.
I've tried a combination of while loop with nested ifs with some conditions like text.startsWith, .endsWith("str", ignorecase: false) something like that for my onclick buttons.
Some code suggestions is highly appreciated.
2-->Also i've been thinking if there's a series of command/code where an individual textview will be created every time characters(created by onclick buttons) formed an integer/expression/decimalnumber(etc) as well as operation(+,-,*,/)
in a way that every number and math operations are separated into textviews(for editing purposes)
I hope someone can give me an idea and codes/commands that I might try to experiment with to develop my app

<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number" />
or
In this sample code, the text in the EditText is first converted to an Int value. If the conversion fails (that is, there is no numeric value in the text box), 0 is set by default. Next, the EditText's text is replaced with the numeric value with the redundant 0's removed.
val editText: EditText = findViewById(R.id.editText)
val number: Int = editText.text.toString().toIntOrNull() ?: 0
editText.setText(number.toString())
allows only text values ​​to be entered
val editText: EditText = findViewById(R.id.editText)
editText.filters = arrayOf(InputFilter { source, _, _, _, _, _ ->
if (source.toString().matches(Regex("[0-9]+"))) {
source
} else {
""
}
})

Related

How to search a string for another string using HTBasic [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am trying to create a program which will search a string for another string, and return the string directly after that string.
Use the POS function to find the substring. Give it the string to search and the string you're looking for and it will return the position it's found at:
POS( S$, T$ )
S$ is the string you're searching
T$ is the string you're looking for
Return value is the position it's found at, or 0 if not found.
The strings are treated as arrays of characters.
A$="hello"
B$=A$[3,4] ! B$ will become "ll"
C$=A$[2] ! C$ will become "ello"
To get everything following the found substring you can use something like this:
1000 DIM A$[72]
1020 A$="Hello World, & goodbye." ! String to search
1040 T$="World, " ! String to look for
1060 L=LEN(T$)
1080 PRINT A$[L+POS(A$,T$)]
1100 END
Running this should give this result:
& goodbye.

Different result for two identical arguments [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I used two IF functions to find the maximum value of a range, but return 0 if I slightly change the function by using AND function. Please help.
This works and returns an integer:
{=MAX(IF(MONTH(A58:A67)=MONTH(K50),IF(YEAR(A58:A67)=YEAR(K50),B58:B67)))}
this one always returns 0:
{=MAX(IF(AND(MONTH(A58:A67)=MONTH(K50),YEAR(A58:A67)=YEAR(K50)),B58:B67))}
Mostly one cannot using AND in array context properly.
In your example the
IF(MONTH(A58:A67)=MONTH(K50),IF(YEAR(A58:A67)=YEAR(K50),B58:B67))
evaluates to
IF({TRUE;FALSE;TRUE;FALSE;...;FALSE}, IF({FALSE;TRUE;TRUE;FALSE;...;TRUE}, {B58:B67}))
dependent on whether MONTH(A58:A67)=MONTH(K50) is TRUE or FALSE and YEAR(A58:A67)=YEAR(K50) is TRUE or FALSE.
That means if the first is TRUE then check the second and if the second also is TRUE, then take the corresponding value from array {B58:B67} into the MAX, else take FALSE, which counts 0, into the MAX.
But
IF(AND(MONTH(A58:A67)=MONTH(K50),YEAR(A58:A67)=YEAR(K50)),B58:B67)
evaluates to
IF(AND({TRUE;FALSE;TRUE;FALSE;...;FALSE},{FALSE;TRUE;TRUE;FALSE;...;TRUE}),{B58:B67})
So both the {TRUE;FALSE;...} arrays are in the AND and that will only be TRUE if there is not a single FALSE in both the arrays, else FALSE which counts 0 in the MAX.
And even if there would not be a single FALSE in both the arrays, then always the whole array B58:B67 would be the result in the MAX.

Dart - How to Insert "$" word in String? [duplicate]

This question already has answers here:
How do you print a dollar sign $ in Dart
(2 answers)
Closed 4 years ago.
I'm currently creating an simple application with flutter(Dart). And when i want to create the AppBar widget, i cant give it names with '$'. Because, same like Kotlin..Dart is using '$' for summoning an identifier.
Any solution?
var _appbar = AppBar(
title: Text("How I Made $100"), //$ is the error
);
The dollar sign is a special character, so if you want it to be ignored you have to escape it with a \.
For example:
void main() {
print("This string contains a dollar \$ign");
}
See this gist.

How to convert a formated string into a one element tuple? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
It is possible to convert a single formatted string into a tuple, for example I am trying to transform a return from a function into a tuple.
E.g:
def GCcontent(self):
"Return GC content of the sequence given"
A = self.get_secuencia().count('A')
T = self.get_secuencia().count('T')
C = self.get_secuencia().count('C')
G = self.get_secuencia().count('G')
content = '{0:.2f}%'.format((G+C)*100/(A+T+G+C))
return content
The output is:
'XX.XX%'
But what I want to get is the following output:
('XX.XX%')
Is this even possible?. I tried tuple() function but it doesn't work as expected, is there another method to achieve this?
tuple([content]) will yield a 1-element tuple whose element is the string in content, but note that when printed, it appears as
('XX.XX%',)

Looking for resources for ICD-9 codes [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
We have been asked by a client to incorporate ICD-9 codes into a system.
I'm looking for a good resource to get a complete listing of codes and descriptions that will end up in a SQL database.
Unfortunately a web service is out of the question as a fair amount of the time folks will be off line using the application.
I've found http://icd9cm.chrisendres.com/ and http://www.icd9data.com/ but neither offer downloads/exports of the data that I could find.
I also found http://www.cms.hhs.gov/MinimumDataSets20/07_RAVENSoftware.asp which has a database of the ICD-9 codes but they are not in the correct format and I'm not 100% sure how to properly convert (It shows the code 5566 which is really 556.6 but I can't find a rule as to how/when to convert the code to include a decimal)
I'm tagging this with medical and data since I'm not 100% sure where it should really be tagged...any help there would also be appreciated.
Just wanted to chime in on how to correct the code decimal places. First, there are four broad points to consider:
Standard codes have Decimal place XXX.XX
Some Codes Do not have trailing decimal places
V Codes also follow the XXX.XX format --> V54.31
E Codes follow XXXX.X --> E850.9
Thus the general logic of how to fix the errors is
If first character = E:
If 5th character = '':
Ignore
Else replace XXXXX with XXXX.X
Else If 4th-5th Char is not '': (XXXX or XXXXX)
replace XXXXX with XXX + . + remainder (XXX.XX or XXX.X)
(All remaining are XXX)
I implemented this with two SQL Update statements:
Number 1, for Non E-codes:
USE MainDb;
UPDATE "dbo"."icd9cm_diagnosis_codes"
SET "DIAGNOSIS CODE" = SUBSTRING("DIAGNOSIS CODE",1,3)+'.'+SUBSTRING("DIAGNOSIS CODE",4,5)
FROM "dbo"."icd9cm_diagnosis_codes"
WHERE
SUBSTRING("DIAGNOSIS CODE",4,5) != ''
AND
LEFT("DIAGNOSIS CODE",1) != 'E'
Number 2 - For E Codes:
UPDATE "dbo"."icd9cm_diagnosis_codes"
SET "DIAGNOSIS CODE" = SUBSTRING("DIAGNOSIS CODE",1,4)+'.'+SUBSTRING("DIAGNOSIS CODE",5,5)
FROM "dbo"."icd9_Diagnosis_table"
WHERE
LEFT("DIAGNOSIS CODE",1) = 'E'
AND
SUBSTRING("DIAGNOSIS CODE",5,5) != ''
Seemed to do the trick for me (Using SQL Server 2008).
I ran into this same issue a while back and ended up building my own solution from scratch. Recently, I put up an open API for the codes for others to use: http://aqua.io/codes/icd9/documentation
You can just download all codes in JSON (http://api.aqua.io/codes/beta/icd9.json) or pull an individual code (http://api.aqua.io/codes/beta/icd9/250-1.json). Pulling a single code not only gives you the ICD-10 "crosswalk" (equivalents), but also some extra goodies, like relevant Wikipedia links.
I finally found the following:
"The field for the ICD-9-CM Principal and Other Diagnosis Codes is six characters in length, with the decimal point implied between the third and fourth digit for all diagnosis codes other than the V codes. The decimal is implied for V codes between the second and third digit."
So I was able to get a hold of a complete ICD-9 list and reformat as required.
You might find that the ICD-9 codes follow the following format:
All codes are 6 characters long
The decimal point comes between the 3rd and 4th characters
If the code starts with a V character the decimal point comes between the 2nd and 3rd characters
Check this out: http://en.wikipedia.org/wiki/List_of_ICD-9_codes
I struggled with this issue myself for a long time as well. The best resource I have been able to find for these are the zip files here:
https://www.cms.gov/ICD9ProviderDiagnosticCodes/06_codes.asp
It's unfortunate because they (oddly) are missing the decimal places, but as several other posters have pointed out, adding them is fairly easy since the rules are known. I was able to use a regular expression based "find and replace" in my text editor to add them. One thing to watch out for if you go that route is that you can end up with codes that have a trailing "." but no zero after it. That's not valid, so you might need to go through and do another find/replace to clean those up.
The annoying thing about the data files in the link above is that there is no relationship to categories. Which you might need depending on your application. I ended up taking one of the RTF-based category files I found online and re-formatting it to get the ranges of each category. That was still doable in a text editor with some creative regular expressions.
I was able to use the helpful answers here an create a groovy script to decimalize the code and combine long and short descriptions into a tab separated list. In case this helps anyone, I'm including my code here:
import org.apache.log4j.BasicConfigurator
import org.apache.log4j.Level
import org.apache.log4j.Logger
import java.util.regex.Matcher
import java.util.regex.Pattern
Logger log = Logger.getRootLogger()
BasicConfigurator.configure();
Logger.getRootLogger().setLevel(Level.INFO);
Map shortDescMap = [:]
new File('CMS31_DESC_SHORT_DX.txt').eachLine {String l ->
int split = l.indexOf(' ')
String code = l[0..split].trim()
String desc = l[split+1..-1].trim()
shortDescMap.put(code, desc)
}
int shortLenCheck = 40 // arbitrary lengths, but provide some sanity checking...
int longLenCheck = 300
File longDescFile = new File('CMS31_DESC_LONG_DX.txt')
Map cmsRows = [:]
Pattern p = Pattern.compile(/^(\w*)\s+(.*)$/)
new File('parsedICD9.csv').withWriter { out ->
out.write('ICD9 Code\tShort Description\tLong Description\n')
longDescFile.eachLine {String row ->
Matcher m = row =~ p
if (m.matches()) {
String code = m.group(1)
String shortDescription = shortDescMap.get(code)
String longDescription = m.group(2)
if(shortDescription.size() > shortLenCheck){
log.info("Not short? $shortDescription")
}
if(longDescription.size() > longLenCheck){
log.info("${longDescription.size()} == Too long? $longDescription")
}
log.debug("Match 1:${code} -- 2:${longDescription} -- orig:$row")
if (code.startsWith('V')) {
if (code.size() > 3) {
code = code[0..2] + '.' + code[3..-1]
}
log.info("Code: $code")
} else if (code.startsWith('E')) {
if (code.size() > 4) {
code = code[0..3] + '.' + code[4..-1]
}
log.info("Code: $code")
} else if (code.size() > 3) {
code = code[0..2] + '.' + code[3..-1]
}
if (code) {
cmsRows.put(code, ['longDesc': longDescription])
}
out.write("$code\t$shortDescription\t$longDescription\n")
} else {
log.warn "No match for row: $row"
}
}
}
I hope this helps someone.
Sean

Resources