在String / txt文件中替换Stuff将dim添加到字符和数字作为值

时间:2022-01-04 05:37:46

I'm trying to figure this out and I just cannot get it to work, I'm stuck please help.

我试图解决这个问题,我无法让它发挥作用,我被困住了请求帮助。

I have a .txt file that will look something like this

我有一个.txt文件,看起来像这样

Example:

例:

GA117.50.0117.50.0117.50.0IL16.08.08.00.016.00.0IN284.09.4274.60.0284.00.0KY137.60.0137.60.0137.60.0TN170.30.0170.30.0170.30.0US725.417.4708.00.0725.40.0TOTAL725.417.4708.00.0725.40.0

GA117.50.0117.50.0117.50.0IL16.08.08.00.016.00.0IN284.09.4274.60.0284.00.0KY137.60.0137.60.0137.60.0TN170.30.0170.30.0170.30.0US725.417.4708.00.0725.40.0TOTAL725.417.4708.00.0725.40.0

What I'm trying to do in classic-asp is to get the letters/word in a dim (and add a str before the letters/word) and the numbers as the value for that dim but only to the first period and 1 more number to the right after the period and then continue to the next letter/word.

我在classic-asp中尝试做的是将字母/单词设置为暗淡(并在字母/单词之前添加一个str),将数字作为该暗淡的值,但仅限于第一个句点和另外1个句点后的数字,然后继续下一个字母/单词。

so the final outcome would look something like this:

所以最终结果看起来像这样:

dim strGA
dim strIL
dim strIN
dim strKY
dim strTN
dim strUS
dim strTOTAL

strGA=117.5
strIL=16.0
strIN=284.0
strKY=137.6
strTN=170.3
strUS=725.4
strTOTAL=725.4

Thank you so much for any help with this problem/question.

非常感谢你对这个问题/问题的任何帮助。

1 个解决方案

#1


3  

Consider the following example.
May need to change the pattern according to the variable names.

请考虑以下示例。可能需要根据变量名更改模式。

Dim strTest
    strTest = "GA117.50.0117.50.0117.50.0IL16.08.08.00.016.00.0IN284.09.4274.60.0284.00.0KY137.60.0137.60.0137.60.0TN170.30.0170.30.0170.30.0US725.417.4708.00.0725.40.0TOTAL725.417.4708.00.0725.40.0"
Dim re
Set re = New RegExp
    re.IgnoreCase = True
    re.Global = True
    re.Pattern = "([a-z]+)(\d+\.\d)"

Dim collMatches
Set collMatches = re.Execute(strTest)
Dim iMatch, strDims, strAssocs
For Each iMatch In collMatches
    strDims = strDims & "Dim str" & iMatch.SubMatches(0) & vbCrLf
    strAssocs = strAssocs & "str" & iMatch.SubMatches(0) & " = " & iMatch.SubMatches(1) & vbCrLf
Next

Dim strExec
strExec = strDims & vbCrLf & strAssocs

'Dump
Response.Write "Dump:<hr /><pre>" & strExec & "<pre>"

ExecuteGlobal strExec 'Execute the code

'Test
With Response
    .Write "Executed:<hr />"
    .Write "strGA: " & strGA & "<br />"
    .Write "strIL: " & strIL & "<br />"
    .Write "strIN: " & strIN & "<br />"
    .Write "strKY: " & strKY & "<br />"
    .Write "strTN: " & strTN & "<br />"
    .Write "strUS: " & strUS & "<br />"
    .Write "strTOTAL:" & strTOTAL & "<br />"
End With

#1


3  

Consider the following example.
May need to change the pattern according to the variable names.

请考虑以下示例。可能需要根据变量名更改模式。

Dim strTest
    strTest = "GA117.50.0117.50.0117.50.0IL16.08.08.00.016.00.0IN284.09.4274.60.0284.00.0KY137.60.0137.60.0137.60.0TN170.30.0170.30.0170.30.0US725.417.4708.00.0725.40.0TOTAL725.417.4708.00.0725.40.0"
Dim re
Set re = New RegExp
    re.IgnoreCase = True
    re.Global = True
    re.Pattern = "([a-z]+)(\d+\.\d)"

Dim collMatches
Set collMatches = re.Execute(strTest)
Dim iMatch, strDims, strAssocs
For Each iMatch In collMatches
    strDims = strDims & "Dim str" & iMatch.SubMatches(0) & vbCrLf
    strAssocs = strAssocs & "str" & iMatch.SubMatches(0) & " = " & iMatch.SubMatches(1) & vbCrLf
Next

Dim strExec
strExec = strDims & vbCrLf & strAssocs

'Dump
Response.Write "Dump:<hr /><pre>" & strExec & "<pre>"

ExecuteGlobal strExec 'Execute the code

'Test
With Response
    .Write "Executed:<hr />"
    .Write "strGA: " & strGA & "<br />"
    .Write "strIL: " & strIL & "<br />"
    .Write "strIN: " & strIN & "<br />"
    .Write "strKY: " & strKY & "<br />"
    .Write "strTN: " & strTN & "<br />"
    .Write "strUS: " & strUS & "<br />"
    .Write "strTOTAL:" & strTOTAL & "<br />"
End With