Ask Question Forum:
Model Library:2025-02-08:A.I. model is online auto reply
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by duncanb7
at 2024-04-07 07:56:21
Point:500 Replies:5 POST_ID:828464USER_ID:11059
Topic:
Hypertext Markup Language (HTML);;Visual Basic Programming
I would like to detele all x:num="A.B" code in my following html paga by VBA,
where A can be any integer and B can any deciaml, I mean the length of A and B is varied
SO Could we look a text starting from "x:num: and ending from ">" and replaced by " " ,
I look at this worksite,http://www.exceltip.com/st/Replace_text_in_a_text_file_using_VBA_in_Microsoft_Excel/468.html
It search exact text string , Is it correct ?
Could you provide me a little code to looping search for example, x=num=*> , where * is anything
The reason to delete it because reducing file size, and it is generated from Excel htm file
Pleasde advise
Duncan
where A can be any integer and B can any deciaml, I mean the length of A and B is varied
SO Could we look a text starting from "x:num: and ending from ">" and replaced by " " ,
I look at this worksite,http://www.exceltip.com/st/Replace_text_in_a_text_file_using_VBA_in_Microsoft_Excel/468.html
It search exact text string , Is it correct ?
Could you provide me a little code to looping search for example, x=num=*> , where * is anything
The reason to delete it because reducing file size, and it is generated from Excel htm file
Pleasde advise
Duncan
<html><body><td class=xl122 bgcolor="#CCFFFF" align=center x:num="5.4310969999999994">10</td><td class=xl122 bgcolor="#CCFFFF" align=center x:num="10.4399994">16</td><td class=xl122 bgcolor="#CCFFFF" align=center x:num="500.4096999994">19</td></body></html> 1:2:3:4:5:6:7:8:
Author: duncanb7 replied at 2024-04-20 07:52:07
Thanks for your reply
Assisted Solution
Expert: aikimark replied at 2024-04-14 07:31:23
250 points EXCELLENT
If you needed to do other clean-up, you could parameterize the attribute string.
To use the RemoveAttribute() function below to do the same thing as the RemoveXnum(), do something like this:
strHTML = RemoveAttribute(strHTML, "x:num=")
To use the RemoveAttribute() function below to do the same thing as the RemoveXnum(), do something like this:
strHTML = RemoveAttribute(strHTML, "x:num=")
Option ExplicitFunction RemoveAttribute(parmString As String, parmAttribute As String) As String Dim lngGTPosn As Long Dim lngSpacePosn As Long Dim lngLoop As Long Dim strThing() As String strThing = Split(parmString, parmAttribute) For lngLoop = 1 To UBound(strThing) If Left$(strThing(lngLoop), 1) = Chr(34) Then 'is first character a quote? lngGTPosn = InStr(1, strThing(lngLoop), ">", vbBinaryCompare) lngSpacePosn = InStr(1, strThing(lngLoop), " ", vbBinaryCompare) If (lngSpacePosn <> 0) And (lngSpacePosn < lngGTPosn) Then strThing(lngLoop) = Mid$(strThing(lngLoop), lngSpacePosn + 1) Else strThing(lngLoop) = Mid$(strThing(lngLoop), lngGTPosn) End If End If Next RemoveAttribute = Join(strThing, "")End Function 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:
Expert: aikimark replied at 2024-04-14 07:10:29
An alternative method is to use the Split() function and then remove the quoted numbers from the start of those strings. In this case, you pass the RemoveXnum() function your HTML string and it returns the cleaned up string.
How you get that HTML isn't part of the stated problem.
How you get that HTML isn't part of the stated problem.
Option ExplicitFunction RemoveXnum(parmString As String) As String Dim lngPosn As Long Dim lngLoop As Long Dim strThing() As String strThing = Split(parmString, "x:num=") For lngLoop = 1 To UBound(strThing) If Left$(strThing(lngLoop), 1) = Chr(34) Then 'is first character a quote? lngPosn = InStr(1, strThing(lngLoop), ">", vbBinaryCompare) strThing(lngLoop) = Mid$(strThing(lngLoop), lngPosn) End If Next RemoveXnum = Join(strThing, "")End Function 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:
Expert: aikimark replied at 2024-04-14 06:51:22
@kaufmed
Even though the HTML sample was shown on separate lines, it isn't reliably stored as CrLf-delimited strings. You might want to read the entire contents of the file and then perform your RegExp parsing.
Even though the HTML sample was shown on separate lines, it isn't reliably stored as CrLf-delimited strings. You might want to read the entire contents of the file and then perform your RegExp parsing.
Accepted Solution
Expert: kaufmed replied at 2024-04-07 08:37:31
250 points EXCELLENT
This should do it:
sourceFile = "input.html"Set reg = New RegExpSet fso = CreateObject("Scripting.FileSystemObject")temp = fso.GetTempName()Set file = fso.OpenTextFile(sourceFile)Set output = fso.CreateTextFile(temp)While Not file.AtEndOfStream source = file.ReadLine() With reg .Pattern = "x:num=""[^""]*""" .Global = True source = .Replace(source, "") End With output.WriteLine(source)Wendoutput.Close()file.Close()Call fso.CopyFile(temp, sourceFile, TRUE)MsgBox "Done!" 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27: