jslegers Posted June 23, 2008 Share Posted June 23, 2008 (edited) Hi, I'm making a script for defragmentation. I use jkdefrag to analyze the drive first. If the fragmented items are above 100 it must start defrag. If not the script must stop. I'm trying a String function to analyze a line like this : 09:23:30 - Number of fragmented items: 55, 0.0321% of all items I need to have the number 55 of this line. But if it is 09:23:30 - Number of fragmented items: 1000, 0.0321% of all items i need the number 1000. I'm looking for a "filter" that returns the fragmented items in a variable, so the number before the , sign. I was thinking of $var1 = StringMid ( $log_c, 40, 3 ) but if it is 1000 this one doesn't work. If I use $var1 = StringMid ( $log_c, 40, 4 ) it will return "55, " Edited June 23, 2008 by jslegers Link to comment Share on other sites More sharing options...
smashly Posted June 23, 2008 Share Posted June 23, 2008 (edited) Sounds like string play, multiple ways to do what your after. StringRegXP would probably be better to use, but I'll leave that upto someone else to figure out$string = "09:23:30 - Number of fragmented items: 1000, 0.0321% of all items" $iRet = StringTrimLeft(StringLeft($string, StringInStr($string, ",", 0, -1) - 1), StringInStr($string, ": ", 0, 1) + 1) ConsoleWrite($iRet & @LF) $string = "09:23:30 - Number of fragmented items: 900, 0.0321% of all items" $iRet = StringTrimLeft(StringLeft($string, StringInStr($string, ",", 0, -1) - 1), StringInStr($string, ": ", 0, 1) + 1) ConsoleWrite($iRet & @LF) $string = "09:23:30 - Number of fragmented items: 90, 0.0321% of all items" $iRet = StringTrimLeft(StringLeft($string, StringInStr($string, ",", 0, -1) - 1), StringInStr($string, ": ", 0, 1) + 1) ConsoleWrite($iRet & @LF) $string = "09:23:30 - Number of fragmented items: 9, 0.0321% of all items" $iRet = StringTrimLeft(StringLeft($string, StringInStr($string, ",", 0, -1) - 1), StringInStr($string, ": ", 0, 1) + 1) ConsoleWrite($iRet & @LF) Cheers Edited June 23, 2008 by smashly Link to comment Share on other sites More sharing options...
jslegers Posted June 23, 2008 Author Share Posted June 23, 2008 Sounds like string play, multiple ways to do what your after. StringRegXP would probably be better to use, but I'll leave that upto someone else to figure out$string = "09:23:30 - Number of fragmented items: 1000, 0.0321% of all items" $iRet = StringTrimLeft(StringLeft($string, StringInStr($string, ",", 0, -1) - 1), StringInStr($string, ": ", 0, 1) + 1) ConsoleWrite($iRet & @LF) Cheers Wow thanks smashly. Link to comment Share on other sites More sharing options...
Kiti Posted June 23, 2008 Share Posted June 23, 2008 At this type of problem, the best thing you can use is StringRegExp. Look at Contents Tab in SciTe Help, under Tutorial, and you'll find "String Regulare Expression". The second example with Gnarly Monster is exactly what you need. Think outside the box.My Cool Lego Technic Website -- see walking bipeds and much more!My YouTube account -- see cool physics experimentsMy scripts:Minesweeper bot: Solves advanced level in 1 second (no registry edit), very improved GUI, 4 solving stylesCan't go to the toilet because of your kids closing your unsaved important work? - Make a specific window uncloseableCock Shooter Bot -- 30 headshots out of 30 Link to comment Share on other sites More sharing options...
smashly Posted June 23, 2008 Share Posted June 23, 2008 Hi your welcome, StringRegXP to do the same thing$string = "09:23:30 - Number of fragmented items: 1000, 0.0321% of all items" $iRet = StringRegExp($string, ": ([0-9]{0,}),", 1, 1) ConsoleWrite($iRet[0] & @LF) $string = "09:23:30 - Number of fragmented items: 900, 0.0321% of all items" $iRet = StringRegExp($string, ": ([0-9]{0,}),", 1, 1) ConsoleWrite($iRet[0] & @LF) $string = "09:23:30 - Number of fragmented items: 90, 0.0321% of all items" $iRet = StringRegExp($string, ": ([0-9]{0,}),", 1, 1) ConsoleWrite($iRet[0] & @LF) $string = "09:23:30 - Number of fragmented items: 9, 0.0321% of all items" $iRet = StringRegExp($string, ": ([0-9]{0,}),", 1, 1) ConsoleWrite($iRet[0] & @LF) Cheers Link to comment Share on other sites More sharing options...
jslegers Posted June 23, 2008 Author Share Posted June 23, 2008 At this type of problem, the best thing you can use is StringRegExp. Look at Contents Tab in SciTe Help, under Tutorial, and you'll find "String Regulare Expression". The second example with Gnarly Monster is exactly what you need.Thanks Kiti the StringRegExp also works : $string = "09:23:30 - Number of fragmented items: 1, 0.0321% of all items" $iRet = StringRegExp( StringTrimLeft ( $string, 39 ), '([0-9]{1,10})', 1) If @error == 0 Then ConsoleWrite($iRet[0] & @LF) Thanks for the help guys. 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