SlimShady Posted June 25, 2004 Share Posted June 25, 2004 (edited) First: I didn't know this was so easy to make This is a function that trims a substring by specifying:the stringFrom which character to start...... until character(s) ...If you know that the string contains a substring multiple times, you can set which occurence to start from.If it doesn't match anything, it will return 1.If the result is an empty string, it will return 2.Requirements:- AutoIt v3.0.102 available belowhttp://www.autoitscript.com/autoit3/files/unstable/autoit/Changes since previous version:- Using the last argument you can tell the function whether you're gonna specify numbers or a string of characters(Examples at the bottom)InformationStringTrim ( "string", "substring 1" , "substring 2" , occurance 1, occurance 2, "type" )Parameters:string The string to evaluate.substring 1 The start of the substring to trim (can be a character string or a number)substring 2 The end of the substring to trim ^^^^ If you specify -1 as the value it will trim everything until the end of the string.occurance 1 Which occurance of substring 1 to find in the string.occurance 2 Which occurance of substring 2 to find in the string."type" Type: "char" or "num"Here's the code:#include-once Func StringTrim($String, $Start, $End, $StartOccur, $EndOccur, $Type) Local $num = 0 If $Type = "char" Then $Match1 = StringInStr($String, $Start, 0, $StartOccur) $Match2 = StringInStr($String, $End, 0, $EndOccur) If $Match1 = 0 Then Return 1 EndIf If $Type = "num" Then $Match1 = $Start $Match2 = $End EndIf If $Match2 < $Match1 Then Do $num = $num + 1 $Match2 = StringInStr($String, $End, 0, $num) If $Match2 = 0 Then Return 1 If @error = 1 Then Return 1 Until $Match2 > $Match1 EndIf If $End = -1 Then $NewString = StringLeft($String, $Match1 - 1) Else $StringLeft = StringLeft($String, $Match1 - 1) $StringRight = StringRight($String, StringLen($String) - $Match2) $NewString = $StringLeft & $StringRight EndIf If $NewString = "" Then Return 2 Return $NewString EndFuncExamples:#include "StringTrim.au3" $String = "[..This is an [..Trim this, please..] example sentence..]" $NewString = StringTrim($String, "[", "]", 2, 1, "char") MsgBox(0, "New String", $NewString) Exit#include "StringTrim.au3" $String = "[..This is an [..Trim this, please..] example sentence..]" $Match1 = StringInStr($String, "[", 0, 2) $Match2 = StringInStr($String, "]", 0, 1) $NewString = StringTrim($String, $Match1, $Match2, 1, 1, "num") MsgBox(0, "New String", $NewString) Exit Edited July 16, 2004 by SlimShady Link to comment Share on other sites More sharing options...
Guest cobra2411 Posted July 14, 2004 Share Posted July 14, 2004 I tried to use the example that you posted, but I recieved an error. The function StringInStr won't take the occurence argument. Am I missing something? Thanks, David Link to comment Share on other sites More sharing options...
jhbell Posted July 14, 2004 Share Posted July 14, 2004 Same problem here. Also in your ExtractURLs Link to comment Share on other sites More sharing options...
SlimShady Posted July 14, 2004 Author Share Posted July 14, 2004 I completely forgot to mention:Those scripts only work with the current beta version of AutoIt:v3.0.102 Available below.http://www.autoitscript.com/autoit3/files/unstable/autoit/ Link to comment Share on other sites More sharing options...
SlimShady Posted July 16, 2004 Author Share Posted July 16, 2004 Updated. 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