Search This Blog

Showing posts with label string. Show all posts
Showing posts with label string. Show all posts

Friday, September 25, 2020

Java Contains Byte String - Back to Original Content String from Byte Array String

Code


String str = "hello";
byte [] x = str.getBytes ();
System.out.println ( new String (x) );
String byStr = "104, 101, 108, 108, 111";
String a [] = byStr.split ( "," );
byte xx [] = new byte[a.length];
int count = 0;
for ( String s :  a)
{
xx[count++] = Byte.parseByte ( s.trim () );
}
System.out.println ( new String (xx) );


Output

hello

hello




Tuesday, February 18, 2020

fasterxml jackson ObjectMapper produces JSON string with '=' and not ':'

Produces [key=value]
new ObjectMapper ().writerWithDefaultPrettyPrinter ().writeValueAsString ( responseVO.toString() )


Produces {"key":"value"}
new ObjectMapper ().writerWithDefaultPrettyPrinter ().writeValueAsString ( responseVO )


Note : Dont convert toString and pass taht to writeValueAsString ()

Tuesday, July 2, 2019

Python - Expecting property key name enclosed in double quotes - String to JSON

import demjson 
result = demjson.decode(' { key: "value" }' )


demjson plugin is very good on this

- Enjoy 

Friday, September 28, 2018

Nodejs code to convert string date to another date format.

Sample nodejs code to convert string date to another format.


date.js

var moment = require('moment');
bar ('1980-08-29', 'YYYY-MM-DD', 'DD/MM/YYYY');    //calling method

function bar(date, currentFormat, requiredFormat )
{
    var date = moment(date,currentFormat);
    var train_date = date.format(requiredFormat);
    console.log(train_date);        // 29/08/1980
    return train_date;
}
exports.bar = bar;



//npm install --save
//node date.js

Hit Counter


View My Stats