SAMPLE FILE IS:[/B]

13301794560@133SH.COM
13301794560@133SH.COM
2205171@MCIMAIL.COM
35988869625@SMS.MTEL.NET

*DESIRED RESULT:

133sh.com
MCIMAIL.COM
sms.mtel.net

When I use the [B]Right* function to get the strings right of "@" it
doesn't give me the desired result, the *Left* function does
give strings right of "@". Any ideas?

CODE

'##############################################################################################
'##############################################

'Textfile to read
sInpFile = "C:\WindowsScripts\vbscript\ExcelList\ListItems.txt"

'Result file
sResultFile = "C:\WindowsScripts\vbscript\ExcelList\clean.txt"

'Character to search
strInput = "@"

' FileSystemObject.CreateTextFile
Const OverwriteIfExist = -1
Const FailIfExist = 0

' FileSystemObject.OpenTextFile

Const FailIfNotExist = 0
Const ForReading = 1
Const ForAppending = 8



Set oFSO = CreateObject("Scripting.FileSystemObject")

' Get list item names into an array:
Set f = oFSO.OpenTextFile (sInpFile,ForReading, FailIfNotExist,
OpenAsASCII)




Dim aListitem()
i = 0
Do Until f.AtEndOfStream
sLine = Trim(f.ReadLine)
If Not sLine = "" Then
ReDim Preserve aListitem(i)
aListitem(i) = sLine
i = i + 1
End If
Loop
f.Close

' Loop through the listitem array


' Create result file
Set fOutputFile = oFSO.CreateTextFile(sResultFile,OverwriteIfExist,
OpenAsASCII)



For Each sItem In aListitem

kline = instr(sItem,strInput)
pline = left(sItem,kline)
fOutputFile.WriteLine pline
kline = 0

Next
'fOutputFile.close

wscript.echo "Process Complete"



--
nnanna
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------

Re: Help with Right function by Martin

Martin
Thu May 26 14:11:37 CDT 2005

Function Right(String, Length As Long)
Member of VBA.Strings
Returns a specified number of characters from the right side of a string

Function Left(String, Length As Long)
Member of VBA.Strings
Returns a specified number of characters from the left side of a string

According to this your code in for section will be:

For Each sItem In aListitem
'
'Your old code
'
'kline = instr(sItem,strInput)
'pline = left(sItem,kline)
'fOutputFile.WriteLine pline
'kline = 0
'
'
'
'Get position of "@" character in given text
'
kline = instr(sItem,strInput)
'
' Left form "@" char
'
pline = left(sItem,kline-1)
'
' Right form "@" char
'
'pline = Right(sItem,Len(sItem)-kline)
'
' You use what you need! Left or Right Side of string according to char
"@"
'
fOutputFile.WriteLine pline
kline = 0

Next

Did i help you? ;-)

"nnanna" <nnanna.1pnptq@mail.codecomments.com> wrote in message
news:nnanna.1pnptq@mail.codecomments.com...
>
> SAMPLE FILE IS:[/B]
>
> 13301794560@133SH.COM
> 13301794560@133SH.COM
> 2205171@MCIMAIL.COM
> 35988869625@SMS.MTEL.NET
>
> *DESIRED RESULT:
>
> 133sh.com
> MCIMAIL.COM
> sms.mtel.net
>
> When I use the [B]Right* function to get the strings right of "@" it
> doesn't give me the desired result, the *Left* function does
> give strings right of "@". Any ideas?
>
> CODE
>
>
'###########################################################################
###################
> '##############################################
>
> 'Textfile to read
> sInpFile = "C:\WindowsScripts\vbscript\ExcelList\ListItems.txt"
>
> 'Result file
> sResultFile = "C:\WindowsScripts\vbscript\ExcelList\clean.txt"
>
> 'Character to search
> strInput = "@"
>
> ' FileSystemObject.CreateTextFile
> Const OverwriteIfExist = -1
> Const FailIfExist = 0
>
> ' FileSystemObject.OpenTextFile
>
> Const FailIfNotExist = 0
> Const ForReading = 1
> Const ForAppending = 8
>
>
>
> Set oFSO = CreateObject("Scripting.FileSystemObject")
>
> ' Get list item names into an array:
> Set f = oFSO.OpenTextFile (sInpFile,ForReading, FailIfNotExist,
> OpenAsASCII)
>
>
>
>
> Dim aListitem()
> i = 0
> Do Until f.AtEndOfStream
> sLine = Trim(f.ReadLine)
> If Not sLine = "" Then
> ReDim Preserve aListitem(i)
> aListitem(i) = sLine
> i = i + 1
> End If
> Loop
> f.Close
>
> ' Loop through the listitem array
>
>
> ' Create result file
> Set fOutputFile = oFSO.CreateTextFile(sResultFile,OverwriteIfExist,
> OpenAsASCII)
>
>
>
> For Each sItem In aListitem
>
> kline = instr(sItem,strInput)
> pline = left(sItem,kline)
> fOutputFile.WriteLine pline
> kline = 0
>
> Next
> 'fOutputFile.close
>
> wscript.echo "Process Complete"
>
>
>
> --
> nnanna
> ------------------------------------------------------------------------
> Posted via http://www.codecomments.com
> ------------------------------------------------------------------------
>