Detect character code automatically