https://github.com/sonsongithub/stringiconv
Decode bytes array to String using iconv.
https://github.com/sonsongithub/stringiconv
Last synced: about 2 months ago
JSON representation
Decode bytes array to String using iconv.
- Host: GitHub
- URL: https://github.com/sonsongithub/stringiconv
- Owner: sonsongithub
- License: mit
- Created: 2017-12-29T22:30:49.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-04-21T09:37:42.000Z (about 7 years ago)
- Last Synced: 2025-02-03T14:47:15.004Z (4 months ago)
- Language: Swift
- Size: 13.7 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# StringIconv
Decode bytes array to String using iconv.
Foundation.framework does not provide a simple decoding method
that discards illegal sequence or transliterate unsupported characters. StringIconv provides a feasible method that statisfies the problem.### case - from Data to String
```
do {
let data = try Data(contentsOf: urlSourceFile)
let string = try String.decode(
data: data,
fromCode: "SHIFT-JIS",
discardIllegalSequence: true,
transliterate: false
)
} catch {
print(error.localizedDescription)
}
```### case - from Data to Data
```
do {
let data = try Data(contentsOf: urlSourceFile)
let decoded: Data = try String.decode(
data: data,
toCode: "UTF8",
fromCode: "SJIS"
)
} catch {
print(error.localizedDescription)
}
```