MS Access 2003 VBA 字符串在换行符处拆分

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1439384/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 10:01:04  来源:igfitidea点击:

MS Access 2003 VBA String Split on Line Break

ms-accessvbaaccess-vba

提问by jim

I have a textbox on a MS Access form that users are going to copy a column of numbers into from an excel spreadsheet. I need to take this input and use it as parameters to build a query. I have code that looks like this

我在 MS Access 表单上有一个文本框,用户将从 Excel 电子表格中复制一列数字。我需要获取此输入并将其用作参数来构建查询。我有看起来像这样的代码

Dim data as variant
Dim input as String
data = Split(input,vbLf)

I want to be able to build a list of the input from the users but I can't figure out how to split it on the line break. I've tried "\n\r", "\n". "\r", vbCrLf, vbLf. The input looks like "12345[][]23456" with the box characters between each number

我希望能够构建用户输入的列表,但我不知道如何在换行符处拆分它。我试过“\n\r”、“\n”。"\r", vbCrLf, vbLf。输入看起来像“12345[][]23456”,每个数字之间有方框字符

Thanks

谢谢

回答by Jay Riggs

I got Split to work for me using vbCrLf. I also wrote the result of Split to a String array.

我让 Split 使用 vbCrLf 对我来说有效。我还将 Split 的结果写入了一个 String 数组。

Here's my code:

这是我的代码:

Dim data() As String
Dim yourInput As String
data = Split(yourInput, vbCrLf)

回答by manji

vbCRLF worked for me, try: Strings.Chr(13) & Strings.Chr(10) (which is vbCRLF)

vbCRLF 对我来说有效,尝试: Strings.Chr(13) & Strings.Chr(10) (which is vbCRLF)

try to see what is the ASCII code of those 2 boxes:

试着看看这两个盒子的 ASCII 码是什么:

    //ex for input = "12345[][]23456"
    Strings.Asc(Strings.Mid(input, 6, 1)) 
    Strings.Asc(Strings.Mid(input, 7, 1))