CyberArmy University | Open Source Institute | CyberArmy Intelligence & Security | CyberArmy Services & Projects

Contd VBScript


[Replies] [Reply] [View by Thread] [Help]
[Back To Programming]

Posted by Delta Cpt dopel On 2008-07-29 03:25:22
In Reply to Programming challenge 3 -easy- Posted by Delta Cpt dopel On 2008-07-20 23:35:30

Delta CptDelta Cpt
Delta Cpt dopel


Dim str, iName, oName, inFile, outFile, fsObj, thisLine


Set fsObj = CreateObject("Scripting.FileSystemObject")
iName = "C:\in.txt"
oName = "C:\out.txt"

Set inFile = fsObj.OpenTextFile(iName, 1)
Set outFile = fsObj.CreateTextFile(oName,1)


While Not inFile.AtEndOfStream
	thisLine = inFile.Readline
	If LCase(strip(thisLine)) = LCase(strip(reverseWord(thisLine))) Then
		outFile.WriteLine(thisLine)
	End If
Wend

inFile.Close()
outFile.Close()

Public Function strip(ByVal str)
	Dim oRegEx, str
	Set oRegEx = New RegExp
	oRegEx.Pattern = "[^a-z0-9]"
	oRegEx.IgnoreCase = True
	oRegEx.Global = True
	str = oRegEx.Replace(str, "")
	strip = str
End Function

Public Function reverseWord(ByVal str)
	Dim i, head, tail, md, ptr

	md = ""	
	ptr = 1
	ub = Len(str)	
	lb = Round((Len(str)/2)+.001)
	If ub = 1 Then
		reverseWord = str
		Exit Function
	End If
	For i = ub To lb+1 Step -1
		head = head & Mid(str, i, 1)
		tail = Mid(str, ptr, 1) & tail
		If (ptr >= i) Then			
			Exit For
		End If
		ptr = ptr + 1
	Next
	If (Len(str) Mod 2) <> 0 Then
		md = Mid(str, lb, 1)
	End If
	
	reverseWord = head & md & tail
End Function



Replies:


Guest:
Subject:
Message:
Signature:
Optional Image Link:
http://

CyberArmy::Forum v0.6
Generated In 0.00785 seconds


About Us | Privacy Policy | Mission Statement | Help