VB.NET - 空字符串 [英] VB.NET - string of nulls

查看:98
本文介绍了VB.NET - 空字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从 CSV 文件中读入的字符串值.CSV 文件包含 7 个 NULL 字节,我已经通过在十六进制编辑器中打开它来确认这一点,并且确实有 7 个 0x0 字节在那里.这个字符串让我很痛苦.

I have a string value read in from a CSV file. The CSV file contains 7 NULL bytes, I have confirmed this by opening it in a hex editor and sure enought there are 7 0x0 bytes in there. This string is causing me pain.

在 vb.net 中,当我检查此字符串的 strlen 时,它返回值 7,如果我执行 String.IsNullOrWhitespace,它返回 false.

In vb.net when I check the strlen of this string it returns a value of 7 and if i do a String.IsNullOrWhitespace it returns false.

我不明白这是为什么?我已将字符串拆分为一个字节数组,每个字节都是 0x0,即空/无.string = Nothing 比较也会失败.

I cannot understand why this is? I have split the string into a byte array and each byte is 0x0, which is null/nothing. A string = Nothing comparison also fails.

我希望能够用我自己的字符串替换此字符串,但我无法动态执行此操作.即使每个字节都是 0x0,为什么这个字符串返回长度为 7 的任何建议?

I want to be able to replace this string with a string of my own but I cannot do this dynamically. Any suggestions why this string returns a length of 7 even though each byte is 0x0?

推荐答案

Null 字符不是空格,并且您的字符串引用不是 Nothing,因此我希望 String.IsNullOrWhitespace() 返回假

The Null character is not whitespace, and your string reference is not Nothing, so I would expect String.IsNullOrWhitespace() to return false

这篇关于VB.NET - 空字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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