从vba中的字符串中删除二进制零 [英] Removeing binary zero from a string in vba

查看:128
本文介绍了从vba中的字符串中删除二进制零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不得不将整个目录结构(数千个目录和文件)从Mac移动到PC,但由于某些原因,现在PC上的某些文件夹名称在结尾处有一个字符值二进制零(一些在中间有这个)。我需要
来清理它,因为它崩溃了一个试图读取这些目录的宏。

 我已经使用Replace函数在vba-word宏中尝试了以下代码(作为遍历目录树的较大程序的一部分,但Replace函数似乎没有捕获chr(0)。


设置current_folder = fso.GetFolder(source_folder.Path)
current_folder_name = current_folder.Name
cleaning_folder_name = Replace(current_folder_name,Chr(0),"")
Selection.TypeText" Old directory name:" &安培; current_folder_name
Selection.TypeParagraph
Selection.TypeText" New directory name:" &安培; cleaning_folder_name
Selection.TypeParagraph
如果current_folder_name<> cleaning_folder_name然后
current_folder.Name = cleaning_folder_name
结束如果

我也尝试过:cleaning_folder_name = Replace(current_folder_name ,Chr(0),",1,-1,vbBinaryCompare)


如何让Replace函数用空格替换字符串中的二进制0。


或者有人知道一种不同的清理这些目录和文件名的方法。


谢谢,Harry

解决方案

微软Visual Basic for Applications(VBA)论坛

I've had to move a whole directory structure (thousands of directories and files) from the Mac to the PC, but now on the PC for some reason some of the folder names have a character on the end of value binary zero ( a few have this in the middle). I need to clean this up since it crashes a macro which tries to read these directories.
 I've tried the following code in a vba-word macro using the Replace function (as part of a larger program that walks through the directory tree) but the Replace function doesn't seem to catch chr(0) .

Set current_folder = fso.GetFolder(source_folder.Path)
current_folder_name = current_folder.Name
cleaned_folder_name = Replace(current_folder_name, Chr(0), " ")
Selection.TypeText "Old directory name: " & current_folder_name
Selection.TypeParagraph
Selection.TypeText "New directory name: " & cleaned_folder_name
Selection.TypeParagraph
If current_folder_name <> cleaned_folder_name Then
    current_folder.Name = cleaned_folder_name
End If

I've also tried: cleaned_folder_name = Replace(current_folder_name, Chr(0), " ", 1, -1, vbBinaryCompare)

How I can get the Replace function to replace binary 0 in a string by a blank.

Or does anyone knows a different approach to cleaning up these directory and file names that would work.

Thanks, Harry

解决方案

Microsofts Visual Basic for Applications (VBA) forum


这篇关于从vba中的字符串中删除二进制零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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