Advertisement
AntonioVillanueva

ByteArray desde String con una funcion

Nov 24th, 2021
881
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. /*
  2.  * Inicializar ByteArray desde String con una funcion
  3.  * Antonio Villanueva Segura  
  4.  */
  5.  
  6. fun main() {
  7.  
  8.     var msg:String ="abcdefg" //Cadena de texto a transformar en ByteArray
  9.    
  10.     //Genero el ByteArray con funcion desde un String
  11.     val arrayGenerado = ByteArray(msg.length){i -> transforma(msg,i)}
  12.    
  13.     //Lectura del Byte Array generado
  14.     for (elem in arrayGenerado){
  15.         println (elem)
  16.     }
  17. }
  18.  
  19. //Recibe la cadena de texto con el indice deseado y retorna un Byte
  20. fun transforma ( msg:String , index:Int):Byte{
  21.     return msg[index].toByte()
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement