How to replace multiple white spaces with one white space
string cleanedString = System.Text.RegularExpressions.Regex.Replace(dirtyString,@”\s+”,” “);
string cleanedString = System.Text.RegularExpressions.Regex.Replace(dirtyString,@”\s+”,” “);
System.out.println(NumberFormat.getNumberInstance(Locale.US).format(35634646)); Output: 35,634,646
As you know the string is coming in as Encoding.Default you could simply use: byte[] bytes = Encoding.Default.GetBytes(myString); myString = Encoding.UTF8.GetString(bytes); Another thing you may have to remember: If you are using Console.WriteLine to output some strings, then you should also write Console.OutputEncoding = System.Text.Encoding.UTF8;!!! Or all utf8 strings will be outputed as gbk…
Assuming one of the delimiters is newline, the following reads the line and further splits it by the delimiters. For this example I’ve chosen the delimiters space, apostrophe, and semi-colon. std::stringstream stringStream(inputString); std::string line; while(std::getline(stringStream, line)) { std::size_t prev = 0, pos; while ((pos = line.find_first_of(” ‘;”, prev)) != std::string::npos) { if (pos > prev) … Read more
Another version… Use strtol, wrapping it inside a simple function to hide its complexity : inline bool isInteger(const std::string & s) { if(s.empty() || ((!isdigit(s[0])) && (s[0] != ‘-‘) && (s[0] != ‘+’))) return false; char * p; strtol(s.c_str(), &p, 10); return (*p == 0); } Why strtol ? As far as I love C++, … Read more
A string instance is immutable. You cannot change it after it was created. Any operation that appears to change the string instead returns a new instance: string foo = “Foo”; // returns a new string instance instead of changing the old one string bar = foo.Replace(‘o’, ‘a’); string baz = foo + “bar”; // ditto … Read more
You need to put the format arguments into a tuple (add parentheses): instr = “‘%s’, ‘%s’, ‘%d’, ‘%s’, ‘%s’, ‘%s’, ‘%s'” % (softname, procversion, int(percent), exe, description, company, procurl) What you currently have is equivalent to the following: intstr = (“‘%s’, ‘%s’, ‘%d’, ‘%s’, ‘%s’, ‘%s’, ‘%s'” % softname), procversion, int(percent), exe, description, company, procurl … Read more
Would this work for your situation? >>> s=”12abcd405″ >>> result=””.join([i for i in s if not i.isdigit()]) >>> result ‘abcd’ This makes use of a list comprehension, and what is happening here is similar to this structure: no_digits = [] # Iterate through the string, adding non-numbers to the no_digits list for i in s: … Read more
If possible you should change the data type of the column to a number if you only store numbers anyway. If you can’t do that then cast your column value to an integer explicitly with select col from yourtable order by cast(col as unsigned) or implicitly for instance with a mathematical operation which forces a … Read more
$newstr = substr_replace($oldstr, $str_to_insert, $pos, 0); http://php.net/substr_replace In the above snippet, $pos is used in the offset argument of the function. offsetIf offset is non-negative, the replacing will begin at the offset’th offset into string. If offset is negative, the replacing will begin at the offset’th character from the end of string.