Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove spaces between numbers

Status
Not open for further replies.

cparralesl

Programmer
Jan 27, 2002
118
NI
Hi Guys,

I've searched thisone previously, without sucess.

My script reads each line from a plaint text file in order to get data and send it to MS-Excel later, but the format numbers contained in it has spaces as thounsands separator instead of a comma (instead 39,1109.90).

What I need to have is the entire number, without space (391109.90 ). The plain text has the "|" as delimiter.

Text plain ej:
| 9 088| 391 109.90| 8 005| 342 326.36|

Code:
set oFO = CreateObject("SAFRCFileDlg.FileOpen")
oFO.OpenFileOpenDlg

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(oFO.FileName)

Do While objTextFile.AtEndOfStream <> True
    curStr = objTextFile.Readline
    If inStr(CurStr, "|") Then
        arrLine = split(CurStr, "|")
	For K=0 To UBound(arrLine)
           Wscript.Echo "Elemento " & K & ": " & Trim(arrLine(K))
	Next
    End If
Loop

Any help will be appreciated and thanks inadvance.



Cesar Humberto Parrales
Application Support
 
I suppose one way could be..

Code:
Option Explicit

Main()

Sub Main()
	Dim arrTemp : arrTemp = Split("|  9 088|  391 109.90|  8 005|  342 326.36|", "|")
	Dim strTemp
	For Each strTemp In arrTemp
		If strTemp <> "" Then WScript.Echo Replace(LTrim(strTemp), " ", ",")
	Next
End Sub

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Why not just:
Code:
Do While objTextFile.AtEndOfStream <> True
    curStr = objTextFile.Readline
    [red]curStr = Replace(curStr," ","")[/red]
    If inStr(CurStr, "|") Then
        arrLine = split(CurStr, "|")
    For K=0 To UBound(arrLine)
           Wscript.Echo "Elemento " & K & ": " & [red]arrLine(K)[/red]
    Next
    End If
Loop
Hope this helps

HarleyQuinn
---------------------------------
Carter, hand me my thinking grenades!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before posting.

 
And a plain old DOS solution

C:\test> type test1.txt
| 9 088| 391 109.90| 8 005| 342 326.36|
| 1 3|999999999.99| 2| 1 3 5 7 9 0|

C:\test> type test1.bat
@echo off
for /F "tokens=1,2,3,4 delims=|" %%i in (test1.txt) do (
set f1=%%i
set f2=%%j
set f3=%%k
set f4=%%l
) & call :process_fields
goto :eof
:process_fields
echo ^|%f1: =%^|%f2: =%^|%f3: =%^|%f4: =%^|
goto :eof

C:\test>test
|9088|391109.90|8005|342326.36|
|13|999999999.99|2|135790|

C:\test>


In order to understand recursion, you must first understand recursion.
 
Thanks guys! I'll try your suggestions and let you know how was it.

I appreciate it.



Cesar Humberto Parrales
Application Support
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top