Today's Question:  What does your personal desk look like?        GIVE A SHOUT

SEARCH KEYWORD -- string format



  Read white space with scanf()

Usually, when we want to enter string with white spaces in C, we need to call gets() or fgets(0 method. We usually will not use scanf(0 or fscanf() because they cannot accept white spaces when scan user inputs.   But when we specify the format in scanf() function, we may read strings with white space. the code section below illustrate this: #include <stdio.h>   int main(int argc,char **argv){        char name[30];      fprintf(stdout,"Please en...

   C,scanf,white space, string format     2011-09-26 11:45:43

  A strange behavior of printing struct with nested struct in GoLang

Normally when trying to print a struct , we would use %v to show all data of the struct. It will print the default format for each field in the struct. %v the value in a default format when printing structs, the plus flag (%+v) adds field names But recently we observed a strange behavior when printing a struct with nested struct which has a String() string implemented, the %v format prints an 'unexpected' output per our understanding.   Let's see the example snippet first. pa...

   PROGRAMMING,GOLANG     2018-10-29 09:59:49

  Be careful about printing error as string in GoLang

In GoLang, we can format and produce string using fmt.Printf(), just like C, GoLang also supports format verbs like %s, %d which can be placeholder for different types of values. But please pay attention when printing error as string so that you will not fall into some trap. Let's first take an example code snippet and see what trap we are talking about. package main import "fmt" type A string func (a A) Error() string { return fmt.Sprintf("%s is an error", a) } func main() { a := A("hello...

   STACKOVERFLOW,GOLANG,FMT     2019-01-23 09:17:15

  JSON in JavaScript

When sending an AJAX request to the server, the response can have two formats : XMLHttpRequest.responseXML to access data with XML format and XMLHttpRequest.responseText to access data with string format. XML is the standard data transfer format, but one weakness is it's troublesome to parse and retrieve the data. JSON(JavaScript Object Notation) is a light weight data interchange format, we call it the JavaScript object representation. The advantage of using JSON as the data format is itself is...

   JSON,JavaScript     2013-05-04 23:25:57

  Using DateInterval class in PHP

DateInterval is (amongst others) a relatively new addition to the date extension in PHP 5.3. It allows to describe an interval in time, and you can perform actions with that interval. Basically, it allows to calculate with dates in a very easy way, and do even more fun stuff with it.Unfortunately no documentation exists today for DateInterval and friends, but PHP is open-source so you can easily have a peek at the code to see what’s happening under the engine. This is more or less what th...

   PHP,DateInterval,Class,PHP 5.3,Demo     2011-10-21 10:35:54

  String intern in Java

In Java, == is used to compare whether two objects have the same memory location, equals() is usually used to compare whether two objects have the same time and the same state.  When comparing two strings, normally we just want to know whether they have same content, so we can choose equals(). But since String comparison is so frequently needed, Java has worked on the String class to make == workable when comparing two String literals. The String class maintains a pool of emp...

   JAVA,STRING     2016-04-10 03:35:25

  Three images to understand immutability of String in Java

String is immutable in Java. This means once a String object is created and instantiated, that object cannot be changed. Any operation on the String object will create a new Object instead of operating on the original content. Below are three images to help you understand String immutability in Java. Declare a String String s = "abcd"; s stores the reference to the string content created in the heap. Assign the String reference to another String variable String s2 = s; s2 stores the same ...

   STRING,JAVA     2016-03-11 20:58:28

  Convert time to Unix time

Unix time is defined as the number of seconds that have elapsed since midnight Coordinated Universal Time (UTC), 1 January 1970,not counting leap seconds. It is used widely in Unix-like and many other operating systems and file formats. It is neither a linear representation of time nor a true representation of UTC. Unix time may be checked on some Unix systems by typing date +%s on the command line. Sometimes it's a bit difficult to compare times stored in different applications or systems with ...

   UNIX time, Oracle DATE, conversion, timestamp     2013-01-19 09:04:17

  C++ : string beginWith and endWith

C++ is an very powerful programming language. It is efficient and flexible. When writing C++ programs, we may often need to process strings and often we need to check whether a string begin with some substring or end with some substring. We can use following functions to ahieve these:     static bool beginWith(const std::string str,const std::string needle){        return (!str.compare(0,needle.length(),needle));    }    ...

   C++,beginWith,endWith,     2012-08-31 06:53:44

  Fuzzy search algorithm in Sublime Text

Fuzzy string searching is the technique of finding strings that match a pattern approximately (rather than exactly. In many editors, we can easily find the Find menu item to do exact matching. While in Sublime Text and some other editors, we can use fuzzy string searching as well if we just want to have an approximate match. There is some algorithm implemented in Sublime Text to implement achieve this. First the search query is split into characters, join them with a regex wildcard, and then run...

   Sublime Text,Fuzzy search     2013-10-14 22:49:38