Jump to content

String search before , sign posible ?


Recommended Posts

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 by jslegers
Link to comment
Share on other sites

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 by smashly
Link to comment
Share on other sites

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

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.

Link to comment
Share on other sites

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

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...