vba Chr(10) 处的单独字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19452979/
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
Separate String at Chr(10)
提问by ruedi
Description:I have a String that is created in a loop:
描述:我有一个在循环中创建的字符串:
PString = PString & Chr(10) & ActiveCell.Offset(i - 2, 0).Value
During the marco I have to separate the strings again at the point Chr(10)
在 Marco 期间,我必须在 Chr(10) 点再次分离琴弦
Problem:I dont know how to search for Chr(10) in the string and separate the string at that point. I tried
问题:我不知道如何在字符串中搜索 Chr(10) 并在该点分隔字符串。我试过
For each PChar in PString
If PChar = Chr(10) then
...
next
but this is not working.
但这不起作用。
采纳答案by Siddharth Rout
search for Chr(10) in the string and separate the string at that point.
在字符串中搜索 Chr(10) 并在该点分隔字符串。
You can use a variant array and use SPLIT()
with Chr(10)
as a delimiter.
您可以使用变体数组并使用SPLIT()
withChr(10)
作为分隔符。
Dim MyAr
Dim PString As String, i As Long
PString = PString & Chr(10) & ActiveCell.Offset(i - 2, 0).Value
PString = PString & Chr(10) & ActiveCell.Offset(i - 3, 0).Value
MyAr = Split(PString, Chr(10))
For i = LBound(MyAr) To UBound(MyAr)
Debug.Print MyAr(i)
Next