Patil Posted November 20, 2007 Share Posted November 20, 2007 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...... Link to comment Share on other sites More sharing options...
ChrisL Posted November 20, 2007 Share Posted November 20, 2007 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 [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
Patil Posted November 20, 2007 Author Share Posted November 20, 2007 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........ Link to comment Share on other sites More sharing options...
Monamo Posted November 20, 2007 Share Posted November 20, 2007 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] Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now