# UniversalCharacterDetectionMBS to TextEncoding

**URL:** <https://forum.xojo.com/t/universalcharacterdetectionmbs-to-textencoding/33143>\
**Category:** General\
**Created:** [August 29, 2016, 5:12pm UTC](https://forum.xojo.com/t/universalcharacterdetectionmbs-to-textencoding/33143 "2016-08-29T17:12:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim\_Parnell](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_parnell/32/161_2.png) [@Tim\_Parnell](https://forum.xojo.com/u/Tim_Parnell)\
**Post date:** [August 29, 2016, 5:12pm UTC](https://forum.xojo.com/t/universalcharacterdetectionmbs-to-textencoding/33143/1 "2016-08-29T17:12:24Z")

</div>

`UniversalCharacterDetectionMBS` returns a string version of the charset it detected, is there an existing good way to get a `TextEncoding` object from MBS based on this, or should I just loop through all the `TextEncoding` `InternetName`s and compare them?

---

<div class="post-metadata">

**Author:** ![Tim\_Parnell](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_parnell/32/161_2.png) [@Tim\_Parnell](https://forum.xojo.com/u/Tim_Parnell)\
**Post date:** [August 29, 2016, 6:11pm UTC](https://forum.xojo.com/t/universalcharacterdetectionmbs-to-textencoding/33143/2 "2016-08-29T18:11:47Z")

</div>

For what it’s worth in the future, this works.

[code]Function GetEncoding(sInput as String) As TextEncoding  
dim oEncodingDetection as new UniversalCharacterDetectionMBS(UniversalCharacterDetectionMBS.FilterAll)  
oEncodingDetection.AddData(sInput)  
oEncodingDetection.Finish

dim sEncodingName as String = oEncodingDetection.LastCharSet  
dim oEncoding as TextEncoding

dim iEncCount as Integer = Encodings.Count - 1  
for i as Integer = 0 to iEncCount  
if sEncodingName = Encodings.Item(i).InternetNameMBS then  
oEncoding = Encodings.Item(i)  
exit  
end  
next

return oEncoding  
End Function  
[/code]

---

<div class="post-metadata">

**Author:** ![Marco\_Hof](https://forum.xojo.com/user_avatar/forum.xojo.com/marco_hof/32/642_2.png) [@Marco\_Hof](https://forum.xojo.com/u/Marco_Hof)\
**Post date:** [August 29, 2016, 7:30pm UTC](https://forum.xojo.com/t/universalcharacterdetectionmbs-to-textencoding/33143/3 "2016-08-29T19:30:35Z")

</div>

I do this…

[code]Function GetEncoding(sInput as String) As TextEncoding  
Dim oEncodingDetection As New UniversalCharacterDetectionMBS(UniversalCharacterDetectionMBS.FilterAll)  
oEncodingDetection.AddData(sInput)  
oEncodingDetection.Finish

Return GetInternetTextEncoding(oEncodingDetection.LastCharSet)  
End Function[/code]  
…but after posting I just noticed that GetInternetTextEncoding is OSX only for some reason.  
Strange.

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 6:26pm UTC](https://forum.xojo.com/t/universalcharacterdetectionmbs-to-textencoding/33143/4 "2020-10-29T18:26:24Z")

</div>


