string-conversion

Check if a string is half width or full width in C#

浪子不回头ぞ 提交于 2019-12-01 21:16:37
C# application on Japanese Windows OS - Present Latin as Full-Width characters I referred the accepted answer in the above link and is using the code below to convert Japanese string from full width to half width but it is returning the same full width string without converting. string userInput = "チヨチヨチチヨチヨチ"; string result = userInput.Normalize(NormalizationForm.FormKC); Expected output in half width: チヨチヨチチヨチヨチ Actual output: チヨチヨチチヨチヨチ (full width) However, even though the above code is supposed to convert a full width string to half width, when I pass the half width string (チヨチヨチチヨチヨチ) to

convert int into string with certain length of char

余生颓废 提交于 2019-12-01 19:50:43
If the title wasn't clear, ill try to explain it well here. I have a bunch of integers, ranging from 1 to 999, and i need to convert these into strings, but when i do that, i need them to be 3 characters long. so for instance, if i had: int i1 = 45; then when i turned that into a string, i'd need this: "045" or similarly, if i had an int of 8 then that would have to turn into "008" , and if anything had 3 places, such as 143, then it would just be outputted as 143. is this easily possible? Thanks for responses in advance. :) string output = someInt.ToString("000"); If you would like to make it

convert int into string with certain length of char

萝らか妹 提交于 2019-12-01 18:57:16
问题 If the title wasn't clear, ill try to explain it well here. I have a bunch of integers, ranging from 1 to 999, and i need to convert these into strings, but when i do that, i need them to be 3 characters long. so for instance, if i had: int i1 = 45; then when i turned that into a string, i'd need this: "045" or similarly, if i had an int of 8 then that would have to turn into "008" , and if anything had 3 places, such as 143, then it would just be outputted as 143. is this easily possible?

Can you cast a LPTSTR to a BSTR?

浪子不回头ぞ 提交于 2019-12-01 15:49:03
Is it legal to cast a LPTSTR directly to a BSTR? Based on my understanding of BSTR , casting a LPTSTR to a BSTR directly will leave you with a corrupted length prefix. The example code explicitly states that a string literal cannot be stored to a BSTR. Can anyone confirm for me that a LPTSTR/LPCTSTR cannot be cast directly to a BSTR without corrupting the length prefix? EDIT: My confusion is from seeing this used in a call to a COM object. It turns out that when compiling the COM dll, a .tli file is generated that creates an intermediate method. This method takes type _bstr_t . The _bstr_t can

inconsistency in converting string to integer, when string is hex, prefixed with '0x'

梦想与她 提交于 2019-12-01 00:37:04
Using PHP 5.3.5. Not sure how this works on other versions. I'm confused about using strings that hold numbers, e.g., '0x4B0' or '1.2e3' . The way how PHP works with such strings seems inconsistent to me. Is it only me? Or is it a bug? Or undocumented feature ? Or am I just missing some magic sentence in docs? <?php echo $str = '0x4B0', PHP_EOL; echo "is_numeric() -> ", var_dump(is_numeric($str)); // bool(true) echo "*1 -> ", var_dump($str * 1); // int(1200) echo "(int) -> ", var_dump((int)$str); // int(0) echo "(float) -> ", var_dump((float)$str); // float(0) echo PHP_EOL; echo $str = '1.2e3'

How to convert st_mtime (which get from stat function) to string or char

怎甘沉沦 提交于 2019-11-30 19:01:44
I need to convert st_mtime to string format for passing it to java layer, i try to use this example http://www.cplusplus.com/forum/unices/10342/ but compiler produce errors invalid conversion from 'long unsigned int*' to 'const time_t* {aka long int const*}' initializing argument 1 of 'tm* localtime(const time_t*)' [-fpermissive] What i doing wrong, how to get time creation of file using stat function in string presentation. Help please. According to the stat(2) man page, the st_mtime field is a time_t (i.e. after reading the time(7) man page, a number of seconds since the unix Epoch ). You

String to binary output in Java

强颜欢笑 提交于 2019-11-30 08:58:21
I want to get binary (011001..) from a String but instead i get [B@addbf1 , there must be an easy transformation to do this but I don't see it. public static String toBin(String info){ byte[] infoBin = null; try { infoBin = info.getBytes( "UTF-8" ); System.out.println("infoBin: "+infoBin); } catch (Exception e){ System.out.println(e.toString()); } return infoBin.toString(); } Here i get infoBin: [B@addbf1 and I would like infoBin: 01001... Any help would be appreciated, thanks! Only Integer has a method to convert to binary string representation check this out: import java.io

C++ convert simple values to string

China☆狼群 提交于 2019-11-30 08:06:23
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 problem? As far as I know the only way of doing this is by specialising the template by the parameter

Converting & to & etc

痴心易碎 提交于 2019-11-30 04:37:27
I want to convert & to &, " to " etc. Is there a function in c# that could do that without writing all the options manually? System.Web.HttpUtility.HtmlDecode() Edit : Note from here that "To encode or decode values outside of a web application, use..." System.Net.WebUtility.HtmlDecode() Use the static method HttpUtility.HtmlEncode to change & to & and " to " . Use HttpUtility.HtmlDecode to do the reverse. Corredera Romain You can use System.Net.WebUtility.HtmlDecode(uri); Server.HtmlDecode . A good article about this subject : Different ways how to escape an XML string in C# Alex W. using

How to convert st_mtime (which get from stat function) to string or char

落爺英雄遲暮 提交于 2019-11-30 02:48:20
问题 I need to convert st_mtime to string format for passing it to java layer, i try to use this example http://www.cplusplus.com/forum/unices/10342/ but compiler produce errors invalid conversion from 'long unsigned int*' to 'const time_t* {aka long int const*}' initializing argument 1 of 'tm* localtime(const time_t*)' [-fpermissive] What i doing wrong, how to get time creation of file using stat function in string presentation. Help please. 回答1: According to the stat(2) man page, the st_mtime