Tutorial by Examples: converti

Converting between encodings is easy with C++11 and most compilers are able to deal with it in a cross-platform manner through <codecvt> and <locale> headers. #include <iostream> #include <codecvt> #include <locale> #include <string> using namespace std; i...
std::ostringstream can be used to convert any streamable type to a string representation, by inserting the object into a std::ostringstream object (with the stream insertion operator <<) and then converting the whole std::ostringstream to a std::string. For int for instance: #include <sst...
If ww have NSDate object, and we want to convert it into NSString. There are different types of Date strings. How we can do that?, It is very simple. Just 3 steps. Create NSDateFormatter Object NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; Set the date format in whi...
If you know the format of the string you are converting (parsing) you should use DateTime.ParseExact Dim dateString As String = "12.07.2003" Dim dateFormat As String = "dd.MM.yyyy" Dim dateValue As Date dateValue = DateTime.ParseExact(dateString, dateFormat, Globalization.C...
Simply use the .ToString overload of a DateTime object to get the format you require: Dim dateValue As DateTime = New DateTime(2001, 03, 06) Dim dateString As String = dateValue.ToString("yyyy-MM-dd") '2001-03-06
Quite often you have a file which was edited within DOS or Windows and you are viewing it under UNIX. This can look like the following when you view the file with vi. First line of file^M Next Line^M And another^M If you wish to remove the ^M, it can be that you delete each ^M by hand. Alter...
Objects that respond to to_proc can be converted to procs with the & operator (which will also allow them to be passed as blocks). The class Symbol defines #to_proc so it tries to call the corresponding method on the object it receives as parameter. p [ 'rabbit', 'grass' ].map( &:upcase ) ...
You can use the following code for going back and forward. if (!function_exists('codepoint_encode')) { function codepoint_encode($str) { return substr(json_encode($str), 1, -1); } } if (!function_exists('codepoint_decode')) { function codepoint_decode($str) { re...
You can use the following code for going back and forward. if (!function_exists('mb_internal_encoding')) { function mb_internal_encoding($encoding = NULL) { return ($from_encoding === NULL) ? iconv_get_encoding() : iconv_set_encoding($encoding); } } if (!function_exists('mb_c...
q = Queue.new q << 1 q << 2 a = Array.new a << q.pop until q.empty? Or a one liner: [].tap { |array| array < queue.pop until queue.empty? }
From MSDN Use the CInt function to provide conversions from any other data type to an Integer subtype. For example, CInt forces integer arithmetic when currency, single-precision, or double-precision arithmetic would normally occur. Assuming that you have 1 button and 2 textbox. If you type...
When either a signed or unsigned integer is converted to a signed integer type, and its value is not representable in the destination type, the value produced is implementation-defined. Example: // Suppose that on this implementation, the range of signed char is -128 to +127 and // the range of un...
Sometimes conversion of primitive types to boxed types is necessary. To convert the array, it's possible to use streams (in Java 8 and above): Java SE 8 int[] primitiveArray = {1, 2, 3, 4}; Integer[] boxedArray = Arrays.stream(primitiveArray).boxed().toArray(Integer[]::new); With lowe...
Use Spliterators.spliterator() or Spliterators.spliteratorUnknownSize() to convert an iterator to a stream: Iterator<String> iterator = Arrays.asList("A", "B", "C").iterator(); Spliterator<String> spliterator = Spliterators.spliteratorUnknownSize(itera...
In this example you will learn how to generate RSA-OAEP key pair and how to convert private key from this key pair to base64 so you can use it with OpenSSL etc. Please note that this process can also be used for public key you just have to use prefix and suffix below: -----BEGIN PUBLIC KEY----- --...
So, have you ever wondered how to use your PEM RSA key pair that was generated by OpenSSL in Web Cryptography API? If the answers is yes. Great! You are going to find out. NOTE: This process can also be used for public key, you only need to change prefix and suffix to: -----BEGIN PUBLIC KEY----- ...
To String Swift let string = String(NSString(data: data, encoding: NSUTF8StringEncoding)) //assuming data is a valid NSData object Objective-C NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; //assuming data is a valid NSData object [string release]; T...
Sometimes you may need to convert a Set to an array, for example to be able to use Array.prototype methods like .filter(). In order to do so, use Array.from() or destructuring-assignment: var mySet = new Set([1, 2, 3, 4]); //use Array.from const myArray = Array.from(mySet); //use destructuring-a...
NSData can be represented as hexadecimal string, similar to what it outputs in its description method. Swift extension NSData { func hexString() -> String { return UnsafeBufferPointer<UInt8>(start: UnsafePointer<UInt8>(bytes), count: length) .reduce(&quo...
Unlike most other JavaScript objects, symbols are not automatically converted into a string when performing concatenation. let apple = Symbol('Apple') + ''; // throws TypeError! Instead, they have to be explicitly converted into a string when necessary, (for example, to get a textual description...

Page 3 of 4