Jump to content

Automatically Removing Characters


Recommended Posts

Hey everyone? I have a little function that I need help adjusting.

Some of the strings I send through it look like this.....

>>>>>>"how to create rap beats online - music beats software"<<<<<<<<<<<<

I want the function to send the string but without the "-".

>>>>>>"how to create rap beats online music beats software"<<<<<<<<<<<<

Here's the function.....

Func _SendTitle($Title)
    Sleep(250)
    ControlSend("Notepad",'','', String($Title))
    ControlSend('[Class:Notepad]', '', 'Edit1', $Title)
    Sleep(250)
EndFunc
Link to comment
Share on other sites

$text = "how to create rap beats online - music beats software"
_SendTitle($text)
Func _SendTitle($Title)
        StringReplace($Title,"-","")
        Sleep(250)
    ControlSend("Notepad",'','', String($Title))
    ControlSend('[Class:Notepad]', '', 'Edit1', $Title)
    Sleep(250)
EndFunc

[font="Impact"] I always thought dogs laid eggs, and I learned something today. [/font]
Link to comment
Share on other sites

$text = "how to create rap beats online - music beats software"
_SendTitle($text)
Func _SendTitle($Title)
        StringReplace($Title,"-","")
        Sleep(250)
    ControlSend("Notepad",'','', String($Title))
    ControlSend('[Class:Notepad]', '', 'Edit1', $Title)
    Sleep(250)
EndFunc

Thanks. How could we make it Global and dynamic so where no matter what string is passed through it, it gets handled the same way as above?
Link to comment
Share on other sites

Thanks. How could we make it Global and dynamic so where no matter what string is passed through it, it gets handled the same way as above?

I'm not sure what you mean by this...

Any string passed to that function will have it's dash removed, is there other functionality that you needed?

[font="Impact"] I always thought dogs laid eggs, and I learned something today. [/font]
Link to comment
Share on other sites

This will replace any punctuation character with or without a leading or trailing space to a single space.

$text = "how to create rap beats online - music beats software"
_SendTitle($text)
Func _SendTitle($Title)
        $Title = StringRegExpReplace($Title, "[\s*[:punct:]]\s*", " ")
        Sleep(250)
    ControlSend("Notepad",'','', String($Title))
    ControlSend('[Class:Notepad]', '', 'Edit1', $Title)
    Sleep(250)
EndFunc

This will return an array where

$aInfo[0] = how to create rap beats online

$aInfo[1] = music beats software

Then you can manipulate the data contained in the array any way that you want.

$text = "how to create rap beats online - music beats software"
$aInfo = _GetTitle($text)
Func _GetTitle($Title)
    Local $aTitle = StringRegExp($Title, ""^([\w\h]*)(?:\h*[\H\W]\h*)([\w\h]*)$"", 1)
    ;; from the beginning of the string, match any word character (A-Z, 0-9 or _) or horizontal space
    ;; Don't match any Non-word or non- horizontal space whether or not it's preceeded or followed by a space
    ;; match any word character (A-Z, 0-9 or _) or horizontal space to the end of the string
    If NOT @Error Then Return $aTitle
    ;; if an error occured in the pattern match then return an error level of 1
    Return SetError(1)
EndFunc
Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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...