string-conversion

C++ convert simple values to string

陌路散爱 提交于 2019-11-29 11:04:01
问题 Right now I use the following piece of code to dummily convert basic types ( int , long , char[] , this kind of stuff) to std::string for further processing: template<class T> constexpr std::string stringify(const T& t) { std::stringstream ss; ss << t; return ss.str(); } however I don't like the fact that it depends on std::stringstream . I tried using std::to_string (from C++11's repertoire) however it chokes on char[] variables. Is there a simple way offering an elegant solution for this

Converting & to & etc

北慕城南 提交于 2019-11-28 23:32:17
问题 I want to convert & to &, " to " etc. Is there a function in c# that could do that without writing all the options manually? 回答1: System.Web.HttpUtility.HtmlDecode() Edit : Note from here that "To encode or decode values outside of a web application, use..." System.Net.WebUtility.HtmlDecode() 回答2: Use the static method HttpUtility.HtmlEncode to change & to & and " to " . Use HttpUtility.HtmlDecode to do the reverse. 回答3: You can use System.Net.WebUtility.HtmlDecode(uri); 回答4: Server

convert a JavaScript string variable to decimal/money

六月ゝ 毕业季﹏ 提交于 2019-11-28 15:13:26
问题 How can we convert a JavaScript string variable to decimal? Is there a function such as parseInt(document.getElementById(amtid4).innerHTML) 回答1: 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. 回答2: You can also use the Number constructor/function (no need for a radix and usable for both

C# convert string to double in locale

我怕爱的太早我们不能终老 提交于 2019-11-28 11:47:10
In my locale the decimal separator is a ','. However I would still like to write a C# application which works with numbers that use the '.' as decimal separator. string b = "0,5"; double db = double.Parse(b); // gives 0.5 string a = "0.5"; double da = double.Parse(a); // gives 5, however i would like to get 0.5 You need to specify the culture as the second argument to double.Parse , e.g. double da = double.Parse(a, CultureInfo.InvariantCulture); Pretty much all of the formatting/parsing methods have overloads taking an IFormatProvider , and the most commonly-specified implementation of

Check if the input is a number or string in C++

心已入冬 提交于 2019-11-28 11:25:16
I wrote the following code to check whether the input(answer3) is a number or string, if it is not a number it should return "Enter Numbers Only" but it returns the same even for numbers. Please suggest me a solution. #include <iostream> #include <string> #include <typeinfo> #include <stdio.h> #include <stdlib.h> #include <ctype.h> using namespace std; int main () { string ques1= "Client's Name :"; string ques2 = "Client's Address :"; string ques3 = "Mobile Number :"; char answer1 [80]; string answer2; int answer3; cout<<ques1<<endl; cin>>answer1; cout<<ques2<<endl; cin>>answer2; cout<<ques3<

What is the difference between Number(…) and parseFloat(…)

前提是你 提交于 2019-11-28 08:20:00
What is the difference between parseInt(string) and Number(string) in JavaScript has been asked previously. But the answers basically focused on the radix and the ability of parseInt to take a string like "123htg" and turn it into 123 . What I am asking here is if there is any big difference between the returns of Number(...) and parseFloat(...) when you pass it an actual number string with no radix at all. James Allardice No. Both will result in the internal ToNumber(string) function being called. From ES5 section 15.7.1 (The Number Constructor Called as a Function): When Number is called as

How to convert array to a string using methods other than JSON?

纵然是瞬间 提交于 2019-11-27 08:32:58
What is a function in PHP used to convert array to string, other than using JSON? I know there is a function that directly does like JSON. I just don't remember. serialize() is the function you are looking for. It will return a string representation of its input array or object in a PHP-specific internal format. The string may be converted back to its original form with unserialize() . But beware, that not all objects are serializable, or some may be only partially serializable and unable to be completely restored with unserialize() . $array = array(1,2,3,'foo'); echo serialize($array); //

conversion from string to json object android

元气小坏坏 提交于 2019-11-27 07:09:16
I am working on an Android application. In my app I have to convert a string to Json Object, then parse the values. I checked for a solution in stackoverflow and found similar issue here link The solution is like this `{"phonetype":"N95","cat":"WP"}` JSONObject jsonObj = new JSONObject("{\"phonetype\":\"N95\",\"cat\":\"WP\"}"); I use the same way in my code . My string is {"ApiInfo":{"description":"userDetails","status":"success"},"userDetails":{"Name":"somename","userName":"value"},"pendingPushDetails":[]} string mystring= mystring.replace("\"", "\\\""); And after replace I got the result as

C# convert string to double in locale

拟墨画扇 提交于 2019-11-27 06:27:37
问题 In my locale the decimal separator is a ','. However I would still like to write a C# application which works with numbers that use the '.' as decimal separator. string b = "0,5"; double db = double.Parse(b); // gives 0.5 string a = "0.5"; double da = double.Parse(a); // gives 5, however i would like to get 0.5 回答1: You need to specify the culture as the second argument to double.Parse, e.g. double da = double.Parse(a, CultureInfo.InvariantCulture); Pretty much all of the formatting/parsing

What is the difference between Number(…) and parseFloat(…)

随声附和 提交于 2019-11-27 05:46:46
问题 What is the difference between parseInt(string) and Number(string) in JavaScript has been asked previously. But the answers basically focused on the radix and the ability of parseInt to take a string like "123htg" and turn it into 123 . What I am asking here is if there is any big difference between the returns of Number(...) and parseFloat(...) when you pass it an actual number string with no radix at all. 回答1: No. Both will result in the internal ToNumber(string) function being called. From