C++/VB - split question

Asked By Carsten Beckermann
08-Jan-10 08:52 AM
Hello

I want to split several lines of text in the TXT file "d:\Names.txt"
They are seperated with an asterix (*).
Like that:
one*two
three*four
five*six
seven *eight


Please remember the added space after seven and after eight.
I want to search for "seven " with a trailing space and replace it with


I have tried that:

Const sNames = "d:\Names.txt"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oNames = oFSO.OpenTextFile(sNames)
aNames = Split(oNames.ReadAll, VbCrLf)


I tried for the last line:
aNames = Split(oNames.ReadAll, *, VbCrLf)

or:
aNames = Split(oNames.ReadAll, "*", VbCrLf)


How should the split command be changed to work for me?
If the asterix is impossible as a delimiter, i can replace the asterixes in
the textfile with another special char.


Greetings
Carsten
VbCrLf
(1)
OFSO
(1)
CreateObject
(1)
ONames
(1)
SNames
(1)
ANames
(1)
DiskusnĂ­m
(1)
Asterixes
(1)
  mayayana replied to Carsten Beckermann
08-Jan-10 10:01 AM
Why did not you look at the help file? There
is only one delimiter in Split. If you want to
split it at vbCrLf and at "*" then that is two
operations. You need to go through the array
of lines split at vbCrLf and do a split on each
of those.

But you do not seem to be providing all of
the details here. The job you are describing
only requires  s = Replace("seven *", NewString)


in
  Petr Danes replied to Carsten Beckermann
08-Jan-10 11:28 AM
I do not think you need the split function at all, Carsten, unless there is
more subsequent processing that you did not tell us about.

Something like this should be all you need.

x = oNames.ReadAll
x = Replace(x,"seven ","eight ")

Pete
Create New Account
help
not what I want at all. Thanks for any help! - -- -- -- -- -- -- -- -- -- -- -- -- -- - Const ForReading = 1 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile _ ("c: \ file1.txt", ForReading) 'CREATING ARRAY1 FROM FILE writeline array3(i) Next VBScript Discussions Active Directory (1) Insensitive (1) Trim (1) Bit (1) CreateObject (1) ReadLine (1) ReadAll (1) Populate (1) A few thoughts: - Don't build a string string1 and string2. . . . Dim A3(), A1, A2, i, i2, i3, s1, s2 A1 = Split(string1, vbcrlf) string2 = Replace(string2, ", ", vbcrlf) A2 = Split(string2, vbCrLf) Redim A3(UBound(A1)) '- -now you can compare each element '- - in A1 to every 2nd then A3(i3) = s1 & ", " & s2 i3 = i3 + 1 end if next next newfile = Join(A3, vbCrLf) '- - you will have to add the extras like '- - trimming spaces, accomodating '- - case-insensitive matches, etc not | what I want at all. | | Thanks for any help! | | - -- -- -- -- -- -- -- -- -- -- -- -- -- - | | Const ForReading = 1 | Set objFSO = CreateObject("Scripting.FileSystemObject") | Set objTextFile = objFSO.OpenTextFile _ | ("c: \ file1.txt", ForReading) | | | 'CREATING ARRAY1 FROM FILE is fine, but I am not sure I get your example: string2 = 3D Replace(string2, ", ", vbcrlf) I have the array defined and am not sure how to define string2 as the
way of doing the same thing? Thanks. Dim oHtml, ws, myText Dim oShell Set oHtml = CreateObject("htmlfile") Set ws = WScript.CreateObject("WScript.Shell") ' Copy the selection. set oShell = CreateObject("WScript.Shell") oShell.SendKeys"^c" ' Convert clipboard data into string. myText = oHtml.parentwindow.clipboardData.getData the first instance. myText = RegEx.Replace(myText, "'") ' convert string back to clipboard: Set oAutoIt = WScript.CreateObject("AutoItX3.Control") oAutoIt.ClipPut(myText) VBScript Discussions CreateObject (1) Expression (1) SendKeys (1) Control (1) Replace (1) Copy (1) MyText (1) What you way of doing the same thing? Thanks. | | | Dim oHtml, ws, myText | Dim oShell | Set oHtml = CreateObject("htmlfile") | Set ws = WScript.CreateObject("WScript.Shell") | | ' Copy the selection. | | set oShell = CreateObject("WScript.Shell") | oShell.SendKeys"^c" | | ' Convert clipboard data into string. | | myText = oHtml.parentwindow.clipboardData.getData
objFile Dim strLine Dim strNumLines Dim strFrank Dim strHeader Dim strFooter Dim strNewText Set objFSO = CreateObject("Scripting.FileSystemObject") Set strLocalFolder = objFSO.GetFolder("C: \ PHFN007") Set WshShell = WScript.CreateObject("WScript.Shell") Const ForReading = 1 Const ForWriting = 2 Const ForAppending = 8 For Each strFile In msgbox i If i = strFrank Then strFooter = Replace(strLine, "BS1", "BS2") Else strNewText = strNewText & strLine & vbCrLf End If End If i = i+1 'if i = 100 Then 'msgbox "100" 'End if Const ForReading = 3D 1 Const ForWriting = 3D 2 Const ForAppending = 3D 8 Set objFSO = 3D CreateObject("Scripting.FileSystemObject") sPath = 3D createobject("wscript.shell").currentdirectory '"C: \ PHFN007" sMask = 3D "PHFN007*.*" Set objLocalFolder = 3D CreateObject("Shell.Application").Namespace(sPath) Set oFilteredItems = 3D objLocalFolder.Items oFilteredItems.Filter SHCONTF_NONFOLDERS, sMask For Each objFile | Dim strLine | Dim strNumLines | Dim strFrank | Dim strHeader | Dim strFooter | Dim strNewText | | | Set objFSO = CreateObject("Scripting.FileSystemObject") | | Set strLocalFolder = objFSO.GetFolder("C: \ PHFN007") | | Set WshShell = WScript.CreateObject("WScript.Shell") | | | | | | | | Const ForReading = 1 | | Const ForWriting = 2 | | Const ForAppending = 8 | | | | | | | | For Each strFile In
your time, consideration and effort, MarceepooNu Sub subShowInHtmlWindow(strTexte) Dim strText strText = strTexte Set objIE = CreateObject("InternetExplorer.Application") objIE.Navigate("about:blank") Set objDoc = objIE.Document.Body strHTML = strText objDoc.InnerHTML = strHTML objIE.Document.Title = "Date String" 'MsgBox strText 'MsgBox objIE.FullName strMsgBoxMsg = objIE.LocationName & vbCrLf & _ objIE.LocationURL vbCrLf & _ 'objIE.Document( 'MsgBox strMsgBoxMsg objIE.Visible = True ' False True ' False objIE.statusbar = True ' False Contents of a Web Page url = "http: / / www.microsoft.com" 'url = "about:blank" Set objHTTP = CreateObject("MSXML2.XMLHTTP") Call objHTTP.Open("GET", url, FALSE) objHTTP.Send WScript.Echo(objHTTP.ResponseText) End Try something like this instead . . . Function GetIEWindowText(sTitle) Dim IE, stype For Each IE In CreateObject("Shell.Application").windows sType = 3D typename(IE.document) if instr(sType, "htmldocument", 1, vbTextCompare) <> 0 Date String" MsgBox GetIEWindowText(strTitle) '''''''''''''''''''''''''''''''''''''''' Function GetIEWindowText(sTitle) Dim IE, stype For Each IE In CreateObject("Shell.Application").windows sType = typename(IE.document) if instr(sType, "htmldocument", 1, vbTextCompare) <> 0 then Date String" | MsgBox GetIEWindowText(strTitle) | '''''''''''''''''''''''''''''''''''''''' | Function GetIEWindowText(sTitle) | Dim IE, stype | | For Each IE In CreateObject("Shell.Application").windows | sType = typename(IE.document) | if instr(sType, "htmldocument", 1, vbTextCompare) <> 0 then Echo sName, "is undefined" End If Next Function GetVersionsInfo() GetVersionsInfo = Join( Array( _ Replace( _ CreateObject( "Wscript.Shell" ).Exec( "%comspec% / c ver" ).Stdout.ReadAll() _ , vbCrLf _ , "" _ ) _ , Join( Array
Arguments(0) End If Function GetCtrlFolder(strFolder) Const ssfCONTROLS = 3 Dim xpShell, xpCtrl Set xpShell = CreateObject("Shell.Application") For Each xpCtrl In xpShell.NameSpace(ssfCONTROLS).Items If xpCtrl.IsFolder Then If Sub Function GetDetailsOf(ByRef xpItem, ByRef xpFolder) Dim str str = xpFolder.GetDetailsOf(xpItem, TYP) & " on " & vbCRLF str = str & xpFolder.GetDetailsOf(xpItem, ADAPTER) str = str & vbCRLF & String(79, "*") & vbCRLF str = WScript.ScriptName&AUTOR& vbCRLF & vbCRLF & str str = str & "Status of '" & xpItem.Name & "' at " str = str & FormatDateTime(Date, vbLongDate vbCRLF GetDetailsOf = str & vbCRLF & xpFolder.GetDetailsOf(xpItem, STATUS) End Function - - ??R Me typed: Const CONFIG = 6 WScript.Echo xpFolder