# UTF-8 String

**URL:** <https://forum.arduino.cc/t/utf-8-string/690427>\
**Category:** Programming\
**Created:** [January 8, 2021, 12:34pm UTC](https://forum.arduino.cc/t/utf-8-string/690427 "2021-01-08T12:34:36Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![aoumnad](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/aoumnad/32/1147365_2.png) [@aoumnad](https://forum.arduino.cc/u/aoumnad)\
**Post date:** [January 8, 2021, 1:20pm UTC](https://forum.arduino.cc/t/utf-8-string/690427/5 "2021-01-08T13:20:14Z")

</div>

the received string "06720631062F0648064A06460648" is formed by the unicode code points (2 bytes) in hex representation of the word ٲردوينو, to display on the serial monitor, it is necessary to transform to utf-8. To do that, i was obliged to cast the string to numbers. But now, i dont know how to cast it back to String

```cpp
void setup() {
    Serial.begin(9600);            
    char UCS2[] = "06720631062F0648064A06460648";    
    uint8_t n = strlen(UCS2);    
    char S[5];  // 4 digits + \0    
    for(uint8_t i = 0; i < n ; i+=4){
        strncpy(S, &UCS2[i], 4);
        uint16_t CP = strtoul(S,NULL,16);
        unicode2utf8(CP);  //inversé [L H]
        Serial.write((byte*)&CP,2);  // little Endian      
    } 
}

void loop() {
}

void unicode2utf8(uint16_t& U){
    // pour points de codes 0 --> u+07FF
    if(U > 127){
        uint8_t UL = (U & 0x003F)| 0B10000000;
        uint8_t UH = (U >> 6)    | 0B11000000;
        U = (UL << 8) | UH ;  //inversé
    }
}

```

---

_[View the full topic](https://forum.arduino.cc/t/utf-8-string/690427)._
