替换 String/txt 文件中的内容将暗淡的字符和数字添加为值

发布于 2025-01-06 20:50:07 字数 637 浏览 1 评论 0原文

我正在尝试解决这个问题,但我无法让它发挥作用,我被困住了,请帮忙。

我有一个 .txt 文件,类似于以下

示例:

GA117.50.0117.50.0117.50.0IL16.08.08.00.016.00.0IN284.09.4274.60.0284.00.0KY137.60.0137.60.0 137.60.0TN170.30.0170.30.0170.30.0US725.417.4708.00.0725.40.0总计725.417.4708.00.0725.40.0

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

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

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

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

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

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

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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

oО清风挽发oО 2025-01-13 20:50:07

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

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文