string-conversion

How to make String value to call specific existed JButton variable name in java?

情到浓时终转凉″ 提交于 2019-12-05 15:06:48
So, I know there is this: int number = Integer.parseInt("5"); String numtxt = Integer.toString(12); double number = Double.parseDouble("4.5"); String numbertxt = Double.toString(8.2); String letter = Character.toString('B'); char letter = "stringText".charAt(0); so on... but what I don't know how to make String value to call existed JButton variable name dynamically; is it even possible? Let's say, I have 4 JButton called btn1, btn2, btn3 and btnFillNumber; I create a String called buttonName; package testing; public class Testing extends javax.swing.JFrame { String buttonName; int num; public

How do you get an unsigned long out of a string?

百般思念 提交于 2019-12-05 01:38:12
问题 What's the safest and best way to retrieve an unsigned long from a string in C++? I know of a number of possible methods. First, converting a signed long taken from atol. char *myStr; // Initalized to some value somehow. unsigned long n = ((unsigned)atol(myStr)); The obvious problem with this is, what happens when the value stored in myStr is larger than a signed long can contain? What does atol retrieve? The next possibility is to use strtoul. char *myStr; // Initalized to some value somehow

MYSQL: How to convert a string into a month (Number) [duplicate]

眉间皱痕 提交于 2019-12-04 13:44:57
This question already has answers here : MySQL MONTHNAME() from numbers (5 answers) Closed 6 years ago . I have the short version of months: JAN, FEB, MAR , etc. and would like to convert them to it's respective numeric value: 1, 2, 3 , etc Also, I would like to be able to change back and forth between the numeric-month-value, to a "short" month name ( JAN, FEB, MAR ) and it's long version ( January, February, March , etc) NOTE: As @dipu-raj pointed out, this is not a duplicate because I am asking the opposite to MySQL MONTHNAME() from numbers and the answer IS different as well BECAUSE it

String.getBytes(charset) has errors for EBCDIC-charset

冷暖自知 提交于 2019-12-04 11:49:08
The String-conversion to EBCDIC via String.getBytes(charset) supplys at least one false result. The character "a" becomes a 0x3f but should be 0x81. public static void convert() throws UnsupportedEncodingException { String data="abcABC"; String ebcdic = "IBM-1047"; String ascii = "ISO-8859-1"; System.out.printf("Charset %s is supported: %s\n", ebcdic, Charset.isSupported(ebcdic)); String result= new String(data.getBytes(ebcdic)); System.out.printf("EBCDIC: %s\n",asHex(result.getBytes())); System.out.printf("Charset %s is supported: %s\n", ascii, Charset.isSupported(ascii)); result= new String

Convert string to number & vice versa complexity

狂风中的少年 提交于 2019-12-03 17:36:55
问题 What would be the complexity of converting a string to its equivalent number or vice versa? Does it change depending on programming language? On the face of it, one needs to traverse the entire string to convert it to a number, so it is O(n) , or is some typecasting used? This doubt came about when I was writing a routine to check if a given number is a palindrome or not. One approach would be to keep dividing the number by the base (here 10), accumulate digits, and put them together at the

How do you get an unsigned long out of a string?

ぃ、小莉子 提交于 2019-12-03 15:50:09
What's the safest and best way to retrieve an unsigned long from a string in C++? I know of a number of possible methods. First, converting a signed long taken from atol. char *myStr; // Initalized to some value somehow. unsigned long n = ((unsigned)atol(myStr)); The obvious problem with this is, what happens when the value stored in myStr is larger than a signed long can contain? What does atol retrieve? The next possibility is to use strtoul. char *myStr; // Initalized to some value somehow. unsigned long n = strtoul(myStr, 0, 10); However, this is a little over complicated for my needs. I'd

Create a Java Date from a String and vise versa

北战南征 提交于 2019-12-02 17:47:23
问题 I have a date in Integer format (YYYYMMDD) . And a start_time as a String (HH:mm 24 hour system) . and a time_duration in hours as a double . int date = 20140214; String start_time = "14:30"; double duration = 50.30; I want to use these 3 values and create 2 Java Date Objects. One is start_date and one is end_date . They should be in the format YYYY-MM-DD HH:mm . And then after I get 2 data Strings like YYYY-MM-DD HH:mm . how can I obtain those previous variables. date , start_time , duration

convert a JavaScript string variable to decimal/money

蓝咒 提交于 2019-12-02 14:16:00
How can we convert a JavaScript string variable to decimal? Is there a function such as parseInt(document.getElementById(amtid4).innerHTML) Yes -- parseFloat . parseFloat(document.getElementById(amtid4).innerHTML); For formatting numbers, use toFixed : var num = parseFloat(document.getElementById(amtid4).innerHTML).toFixed(2); num is now a string with the number formatted with two decimal places. You can also use the Number constructor/function (no need for a radix and usable for both integers and floats): Number('09'); /=> 9 Number('09.0987'); /=> 9.0987 Sanjay This works: var num =

Converting character string to integer

浪尽此生 提交于 2019-12-02 06:47:22
问题 This is a follow up to my get_command_argument() question. I'm reading a command line argument ( arg ) into a Fortran program. Then I want to store the value of arg as an integer. ichar() doesn't do the job. This seems kind of basic, so clearly I'm doing something wrong. Any hints? program test_get_command_argument integer :: i,j character(len=32) :: arg i = 0 do call get_command_argument(i,arg) if (LEN_TRIM(arg) == 0) EXIT write (*,*) trim(arg) i = i + 1 end do j = ichar(arg) end program 回答1

To convert a ethereum_types::H256 to String in Rust

冷暖自知 提交于 2019-12-02 01:35:03
问题 when I tried to convert ethereum_types::H256 to String by using to_string() use ethereum_types::H256; fn main() { let s = H256::zero(); println!("{}", s); } I expect output to be "0x0000000000000000000000000000000000000000000000000000000000000000" but output is "0x0000…0000" 回答1: This (weird) behaviour comes from the fixed-hash crate. It implements several formatting traits: Display which always elides the middle of the hash. Debug which is equivalent to LowerHex alternate mode. LowerHex and