Jump to content
Sign in to follow this  
Patil

Is their any function to remove new line character

Recommended Posts

Patil

Hi,

In shell script we have a "chop" and a "chomp" to remove last line characters and new line characters,

Like wise do we have any command or function to remove last line character.

$file = FileOpen("C:\Documents and Settings\santosh\Desktop\test.txt", 0)

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

While 1

$line = FileReadLine($file)

If @error = -1 Then ExitLoop

$string = StringSplit($line,",")

for $str in $string

$result = StringCompare($str, "manager")

MsgBox(0, "String of :",$str)

Next

WEnd

Here is my code, what m doing in this is opening the file named test.txt and reading the file line by line and printing the each string and also i have attached the file.

While printing it is printing 2 at the first and after the line break how can i remove that......

Thanks......

Share this post


Link to post
Share on other sites
ChrisL

Hi,

In shell script we have a "chop" and a "chomp" to remove last line characters and new line characters,

Like wise do we have any command or function to remove last line character.

$file = FileOpen("C:\Documents and Settings\santosh\Desktop\test.txt", 0)

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

While 1

$line = FileReadLine($file)

If @error = -1 Then ExitLoop

$string = StringSplit($line,",")

for $str in $string

$result = StringCompare($str, "manager")

MsgBox(0, "String of :",$str)

Next

WEnd

Here is my code, what m doing in this is opening the file named test.txt and reading the file line by line and printing the each string and also i have attached the file.

While printing it is printing 2 at the first and after the line break how can i remove that......

Thanks......

Do you mean can you replace the carrage return at teh end of the line?

There are several ways you can do this

StringStripCR() is one but that would still leave you with @LF You could use stringReplace($str,@crlf,"") to replace all @crlf's with nothing

Or split the file into an array by the @crlf's

$file = FileOpen("C:\Documents and Settings\santosh\Desktop\test.txt", 0)
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

$wholeFile = FileRead($file)
$aWholeFile = StringSplit($wholeFile,@crlf,1)
For $i = 1 to Ubound($aWholeFile) -1
    $string = StringSplit($aWholeFile[$i],",")
    for $str in $string
        $result = StringCompare($str, "manager")
        MsgBox(0, "String of  :",$str)
    Next
Next

Share this post


Link to post
Share on other sites
Patil

Do you mean can you replace the carrage return at teh end of the line?

There are several ways you can do this

StringStripCR() is one but that would still leave you with @LF You could use stringReplace($str,@crlf,"") to replace all @crlf's with nothing

Or split the file into an array by the @crlf's

$file = FileOpen("C:\Documents and Settings\santosh\Desktop\test.txt", 0)
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

$wholeFile = FileRead($file)
$aWholeFile = StringSplit($wholeFile,@crlf,1)
For $i = 1 to Ubound($aWholeFile) -1
    $string = StringSplit($aWholeFile[$i],",")
    for $str in $string
        $result = StringCompare($str, "manager")
        MsgBox(0, "String of  :",$str)
    Next
Next
Fine thanks for the rply......

but it won't work for my reply.......

may be i am wrong i mean i thought it was the problem for curriage return, could you please run the script in result i am getting the index value for the first time. in your code while printing the $str for the first its displaying index value, i want to remove that value........

Share this post


Link to post
Share on other sites
Monamo

Fine thanks for the rply......

but it won't work for my reply.......

may be i am wrong i mean i thought it was the problem for curriage return, could you please run the script in result i am getting the index value for the first time. in your code while printing the $str for the first its displaying index value, i want to remove that value........

Assuming it *wasn't* removal of the carriage return you were actually after, but rather just a method to prevent the array index value "return" -

This would display your data without the "index value" for the $string array:

$file = FileOpen("C:\Documents and Settings\santosh\Desktop\test.txt", 0)
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    $string = StringSplit($line, ",")
    For $i = 1 To $string[0]
        $result = StringCompare($string[$i], "manager")
        MsgBox(0, "String of :", $string[$i])
    Next
WEnd

- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×