如何修剪字节数组? [英] How to trim a byte array?

查看:58
本文介绍了如何修剪字节数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将字节数组修剪为空白.目前,我将字节数组转换为流,从流中获取字符串(因为我知道字节数组仅包含一个字符串),修剪字符串并将其转换回字节数组.有比这种复杂的方法更好的方法吗?谢谢!

I am in need of trimming a byte array for whitespaces. Currently I convert the byte array to a stream, get the string from the stream (since I know that the byte array contains only a string), trim the string and convert it back to a byte array. Is there a better way of doing it than this convoluted approach? Thanks!

推荐答案

获取一个空格字符的数字(我认为是32),然后看一下数组的结尾和/或开头,并删除它们.小心您是否使用unicode.
Get the number for the char of a space (I think it's 32) and look and the end and/or start of your array and remove them. Watch out if your in unicode.


这篇关于如何修剪字节数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆