0

"("常に で始まり で終わる特定の部分をテキスト行から単純に削除する作業コードを取得したいと思います")"

サンプルテキスト :Hello, how are you (it is a question)

この部分を削除したい:"(it is a question)"このメッセージのみを保持する"Hello, how are you"

失った...

ありがとう

4

3 に答える 3

1

正規表現を使用する 1 つの方法。

input = "Hello, how are you (it is a question)"

dim re: set re = new regexp
with re
    .pattern = "\(.*\)\s?" '//anything between () and if present 1 following whitespace
    .global = true

    input = re.Replace(input, "") 
end with

msgbox input
于 2013-03-28T11:02:08.170 に答える
1

削除する部分が常に文字列の最後にある場合、文字列操作も同様に機能します。

msg = "Hello, how are you (it is a question)"

pos = InStr(msg, "(")

If pos > 0 Then WScript.Echo Trim(Left(msg, pos-1))
于 2013-03-28T11:42:48.437 に答える
0

文が常に ( ) セクションで終わる場合は、split 関数を使用します。

line = "Hello, how are you (it is a question)"

splitter = split(line,"(")        'splitting the line into 2 sections, using ( as the divider
endStr = splitter(0)              'first section is index 0

MsgBox endStr                     'Hello, how are you

文の途中にある場合は、split 関数を 2 回使用します。

line = "Hello, how are you (it is a question) and further on"

splitter = split(line,"(")
strFirst = splitter(0)             'Hello, how are you

splitter1 = split(line,")")        
strSecond = splitter1(UBound(Splitter1))    'and further on

MsgBox strFirst & strSecond        'Hello, how are you and further on

「( )」のインスタンスが 1 つしかない場合は、UBound の代わりに「1」を使用できます。複数の例では、文を分割してから、「( )」を含む各セクションを分解し、最後の文を連結します。

于 2016-12-17T19:40:52.753 に答える