Jump to content
Sign in to follow this  
LetsAuto

extract a string in a .txt as a string variable?

Recommended Posts

LetsAuto

Hi everyone! (again).. :bye:

I am trying to cross-reference user input with a .txt file.. or at least thats what the plan is.. before i get way too heavily involved.. is it possible to have the user input a date (November 6 2012) and then search a .txt file that has "November 6 2012 : xxxxx:xxxxx:xxxxx" and pull out the xxxxx:xxxxx:xxxxx, and use that as a string? OR, should i transfer that data into a global array?

THANKS@

Share this post


Link to post
Share on other sites
DicatoroftheUSA

Yes both methods of what you ask for is possible

read the help file about "FileReadLine"

However depending on the search frequency and the size of the file, you may be better off just using file read, then splitting the string into a 2darray so that a binary search can be performed.

If the file is huge, then I would suggest looking into sqlite.

Share this post


Link to post
Share on other sites
guinness

You could also look at using FileRead and StringRegExp.


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
LetsAuto

okay, so say if i want to display the xxxxx:xxxxx:xxxxx from the November 6 2012 ... line, should I use FileRead and then use StringRegExp A to match the date with the Novmeber 6 2012, then display lineX(x being the line with the correct information)... but how do i tell FileRead to only print out 1 line?

Share this post


Link to post
Share on other sites
DicatoroftheUSA

Fileread and filereadline are different. The help file gives examples of use.

Yes stringregex can be used, by default it searches each line as a segment.

Hit the help file and make a rough draft, and we can give more specific advice.

Edited by DicatoroftheUSA

Share this post


Link to post
Share on other sites
DicatoroftheUSA

Here is an example script

#include
$sFile='November 6 2012 : xxxxx:xxxxx:xxxxx'&@crlf&'November 7 2012 : xxxxx:xxxxx:xxxxx'
$sMonth='November'
$iDay=6
$iYear=2012

$sSearchDay='('&$sMonth&" "&$iDay&" "&$iYear&'.*)'
$aResult=StringRegExp($sFile,$sSearchDay,3)
_ArrayDisplay($aResult)
MsgBox(0,"test",$aResult[0])

Share this post


Link to post
Share on other sites
LetsAuto

;;;;
Global $gArrayOne [0][0] = "Jul"
Global $gArrayOne [0][1] = "xxxxxxxxxxxxxxxxxxxxxxx="
Global $gArrayOne [1][0] = "Aug"
Global $gArrayOne [1][1] = "xxxxxxxxxxxxxxxxxxxxxxx="
Global $gArrayOne [2][0] = "Sep"
Global $gArrayOne [2][1] = "xxxxxxxxxxxxxxxxxxxxxxx="
;;;;
Global $gArrayTwo [0][0] = "1 Server"
Global $gArrayTwo [0][1] = "ffffffffffffffffffffffff="
Global $gArrayTwo [1][0] = "5 Servers"
Global $gArrayTwo [1][1] = "ffffffffffffffffffffffff="
Global $gArrayTwo [2][0] = "10 Servers"
Global $gArrayTwo [2][1] = "ffffffffffffffffffffffff="
Global $gArrayTwo [3][0] = "20 Servers"
Global $gArrayTwo [3][1] = "ffffffffffffffffffffffff="
;;;;


$example = InputBox("one", "Please enter month(Jan, Feb, Mar...): ")

if $example == $gArrayOne[0][0] Then
MsgBox("","july code", $gArrayOne[0][1])
endif

so this isnt using StringRegExp.. but do you think that even doing this would work? something simple, if the user input = = gArray[0][0] then display gArray[0][1].. but its saying something is wrong at the end of Global $gArrayOne... line.

Share this post


Link to post
Share on other sites
LetsAuto

mainly becausae i need to be able to search the user input, and i need to display only the code, the xxxxxxxxxxxxxxxx or the ffffffffffffffffff part. and on my GUI, depending on which button the user presses it will either search the x's for the f's which is easy enough to do.

Share this post


Link to post
Share on other sites
BrewManNH

You're redeclaring the array with every line, destroying it's contents in the process, not adding information into it. Declare the array once with Global, then add the information into the elements.

Also, unless you're only expecting the information from the inputbox to be typed exactly the same as the information in the array, don't use "==", that is used for a case sensitive string comparison, and not a normal comparison.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
DicatoroftheUSA

You only define a variable global variable once, and in defining it, give it its scale and dimensions.

ie

Global $gArrayOne [$maxrows][$maxcolums]

$gArrayOne [0][0] = "Jul"

$gArrayOne [0][1] = "xxxxxxxxxxxxxxxxxxxxxxx="

$gArrayOne [1][0] = "Aug"

...

See the help file under autoit -> language reference -> datatypes/variables

Edited by DicatoroftheUSA

Share this post


Link to post
Share on other sites
LetsAuto

Awesome, thanks guys! i got the global arrays to work, I think for simplicity's sake, im going to use the arrays, granted its a lot of lines, it works and i know how to use them now

Share this post


Link to post
Share on other sites
DicatoroftheUSA

Awesome, thanks guys! i got the global arrays to work, I think for simplicity's sake, im going to use the arrays, granted its a lot of lines, it works and i know how to use them now

From the look of your arrays, you might also look into the INI functions. It may be easier to manager.

Share this post


Link to post
Share on other sites
LetsAuto

okay thanks.. also this is completely off topic... how do i save the user's choice for a radio button for later reference, and the later reference is a different file completely, (i told autoIt to run another autoit script) but i need that radio button information in order for most of this to work properly

Share this post


Link to post
Share on other sites
DicatoroftheUSA

If it's off topic another thread should be started so that people who have the same questions as you won't get confused.

But to be honest, I don't get what you are asking for.

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • xiantez
      By xiantez
      This script used to work on an older version of AutoIT. Currently I am running AutoIT v3.3.14.5 and it's failing.
      Func PublicIP() ;Post public facing IP address Local $url = 'https://www.google.com/search?client=opera&q=what+is+my+ip&sourceid=opera&ie=UTF-8&oe=UTF-8' Local $getIPaddress = BinaryToString(InetRead($url)) Local $sStart = 'clamp:2">' Local $sEnd = '</div>' Local $ipaddress = _StringBetween($getIPaddress, $sStart, $sEnd For $i In $ipaddress MsgBox(0, 'External IP', "Your public IP address is " & $i) Next EndFunc ;==>PublicIP The console output shows:
      "C:\Users\user\Documents\AutoIT\Scripts\WSI Tools.au3" (197) : ==> Variable must be of type "Object".: For $i In $ipaddress For $i In $ipaddress^ ERROR ->14:12:16 AutoIt3.exe ended.rc:1 +>14:12:16 AutoIt3Wrapper Finished. >Exit code: 1 Time: 9.811
    • Rskm
      By Rskm
      Hi, I have the following line in a text file 'input.txt'. I know the line number - say '6'. I wish to replace the text 'WWW' in the below line with a random number (I can generate that with random()).
      WERIS  WWWJP   3.83  8.330  1.000                1097.RAXX 
      The WWW is a 3 digit integer (could be any number between 0 to 999), I can use stringtrimleft and get the numerical value of WWW in this file
      so, basically, I know the string to replace (ie; WWW stored in a variable), I know the line number to work on and the file location/name and the replacement variable (through random()). My requirement is to fill that 3 spaces with my random number (which Is a integer between 1 and 999)
      please put ur suggestions
       
    • AndyS19
      By AndyS19
      I'm trying to implement a Ctl-F popup box that looks something like the one that Notepad uses, but I'm not havine much luck.  I intend to get it working, then beef up the popup's contents to add several checkboxes, buttons and radio boxes.
      What my example code does is to use InputBox(), but that's not what I want.
      Here is my test code:
      #include <Array.au3> #include <GUIConstantsEx.au3> #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 Opt("GUICloseOnESC", 1) Opt("GUIOnEventMode", 1) Opt('MustDeclareVars', 1) OnAutoItExitRegister("ExitStageLeft") Opt("WinTitleMatchMode", -2) Global $hGUI _Main() Func _Main() $hGUI = GUICreate("Test ^F", 300, 200) setupSpecialKeysHandlers() GUISetOnEvent($GUI_EVENT_CLOSE, "Event_GUIClose") GUISetState() While (1) Sleep(157) WEnd EndFunc ;==>_Main Func handle_CTRL_F_key() Local $str $str = InputBox("Search", "Enter the string to search for:") ConsoleWrite("+++: $str ==>" & $str & "<==" & @CRLF) EndFunc ;==>handle_CTRL_F_key Func ExitStageLeft() Exit (99) EndFunc ;==>ExitStageLeft Func Event_GUIClose() Exit (1) EndFunc ;==>Event_GUIClose Func setupSpecialKeysHandlers() Local $ar, $parts, $key, $handler, $id Local $aAccelKeys[1][2] ; Create a table of Special keys and their handlers $ar = StringSplit("", "") _ArrayAdd($ar, "^f - handle_CTRL_F_key ") ReDim $aAccelKeys[UBound($ar) - 1][2] ; Now, create $aAccelKeys array with the table data. ; For each entry, create a Dummy GUI and associate its ; ID with the special key. For $ndx = 1 To UBound($ar) - 1 $parts = StringSplit($ar[$ndx], "-", 2) $key = StringStripWS($parts[0], 8) $handler = StringStripWS($parts[1], 8) $id = GUICtrlCreateDummy() $aAccelKeys[$ndx - 1][0] = $key $aAccelKeys[$ndx - 1][1] = $id GUICtrlSetOnEvent($id, $handler) Next GUISetAccelerators($aAccelKeys) ; Setup the Special keys hooks EndFunc ;==>setupSpecialKeysHandlers  
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      I am working with Word UDF ( thanks @water! ), and, especially, with the function _Word_DocFindReplace().
      The replace does work everywhere in the document, but, it does not work in Headers or Footers.
      Am I missing something or am I forced to use the code below?
      I have already looked in the Help file ( about _Word_DocFindReplace() ), but there are no mentions about replace text in Headers/Footers.
      Sub FindAndReplaceFirstStoryOfEachType() Dim rngStory As Range For Each rngStory In ActiveDocument.StoryRanges With rngStory.Find .Text = "find text" .Replacement.Text = "I'm found .Wrap = wdFindContinue .Execute Replace:=wdReplaceAll End With Next rngStory End Sub Thanks everyone in advance


      Best Regards.
    • Atoxis
      By Atoxis
      Howdy, I've gone through a lot of au3 forums, and I once had a working Imagesearch script that I got from here.  However, and i'm just totally not sure how but my imagesearch scripts aren't working anymore.
      I'm not new to au3 but i'm not the most experienced with it's syntax/commands.

      Anyways, I've looked over the big threads involving imagesearch.

      Does anyone have a working Imagesearch x64 for win10 that is currently working as of the date with the post.

      Dll's and what not is fine, just when I tell the script to run, I want to be able to find the image on the screen!
      Can't find a working copy so if anyone has one please send it my way lol.

      I've taken all the imagesearch downloads and what not and have played with them but I can't get any of them working on my end, despite others saying they're working.
      Thanks.
×