No code I'm afraid. What I am trying to do is covered by several document explanations and I cant get it.
I have the haystack (a simple .txt file). I input the needle (which is a product code) into a guí. The next 30 characters after the found needle is the product description. I need to assign the 30 characters a variable which will be returned to the gui (which I can do.) I can't work out how to assign the 30 characters after the needle a variable.
Of course any suggestions will be dealt with with love.
Assign string a variable
Re: Assign string a variable
You input the product code and expect to get the product description in return, right?
Re: Assign string a variable
Hi,
Here's a way to achieve this using SubStr, InStr and StrLen functions.
Here's a way to achieve this using SubStr, InStr and StrLen functions.
Code: Select all
haystack := "AutoHotkey aka AHK. description: Automation scripting language."
needle := "description: "
needleLength := StrLen(needle)
position := InStr(haystack, "description: ")
cuantosCaracteres := 10
substring := SubStr(haystack, position+needleLength, cuantosCaracteres)
MsgBox % substring
substring := SubStr(haystack, InStr(haystack, "description: ")+StrLen(needle), cuantosCaracteres)
MsgBox % substring
- FanaticGuru
- Posts: 1906
- Joined: 30 Sep 2013, 22:25
Re: Assign string a variable
Little simplier with RegEx:A_AhkUser wrote:Hi,
Here's a way to achieve this using SubStr, InStr and StrLen functions.
Code: Select all
haystack := "AutoHotkey aka AHK. description: Automation scripting language." needle := "description: " needleLength := StrLen(needle) position := InStr(haystack, "description: ") cuantosCaracteres := 10 substring := SubStr(haystack, position+needleLength, cuantosCaracteres) MsgBox % substring substring := SubStr(haystack, InStr(haystack, "description: ")+StrLen(needle), cuantosCaracteres) MsgBox % substring
Code: Select all
haystack := "AutoHotkey aka AHK. description: Automation scripting language."
needle := "description: "
cuantosCaracteres := 10
RegExMatch(haystack, needle "(.{" cuantosCaracteres "})", Match)
MsgBox % Match1
Code: Select all
haystack := "Product ID 56412-3889 a string less than 30"
needle := "56412-3889"
RegExMatch(haystack, needle "(.{1,30})", Match)
MsgBox % Match1
haystack := "Product ID 56412-3889 a simple string that is 30. And then stuff you don't want"
needle := "56412-3889"
RegExMatch(haystack, needle "(.{1,30})", Match)
MsgBox % Match1
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
Re: Assign string a variable
Thanks for replying. I accidentally deleted my GUI. Well to save time I used it as a template for another GUI and pressed save instead of saving it under another name so I'll have to sit one day and recreated it. I did check out the codes above for functionality and I was able to get the shorter of the codes to give back some anticipated responses.
Thanks
Thanks
Who is online
Users browsing this forum: Ineedhelplz, jaka1, penguinautomator, Spawnova and 279 guests