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

    • Skeletor
      By Skeletor
      Hi Guys,
      Is it possible to get a variable on your For..Next loop? 
       
      Local $Lines1 = _FileCountLines(C:\temp\test.txt) Local $linesToCount2 = $Lines1 + 2 $var = Number($linesToCount2) For $count = 1 To _FileCountLines($FileRead2) Step 1 For $i = $var To $count Next ;Code does stuff here Next Somehow my code doesn't work even though I thought I could convert the variable to a Integer / Number.
      This code I posted above does not move to the next value.
      But the code below does... why is that?
      For $count = 1 To _FileCountLines($FileRead2) Step 1 For $i = 2 To $count Next ;Code does stuff here Next  
      Why is the For loop resetting itself?
      Is it because the program does not cache the variable and needs to keep on acquiring this variable each time?
      If so , how would you make this variable static?

       
    • Miliardsto
      By Miliardsto
      I got that func
      Func makeHelpImgGUI($title,$width,$height,$img) $img = GUICtrlCreatePic("",20,40,$width,$height) _ResourceSetImageToCtrl($img, "HERE") EndFunc and I call this func like that
      makeHelpImgGUI("Image",1190, 800,$SETTINGS_JPG)  
      so what is the problem in the parameter where is - "HERE" I need value of img but passed as string
      so $img = $SETTINGS_JPG and how make it "SETTINGS_JPG"
       
      I tried something like that but not work
      Func makeHelpImgGUI($title,$width,$height,$img) $name_str = String($img) $name_str = StringTrimLeft ($name_str, 1 ) $img = GUICtrlCreatePic("",20,40,$width,$height) _ResourceSetImageToCtrl($img, $name_str) EndFunc  
    • liagason
      By liagason
      Hello everyone,
      How can I display in ascending  sequence some numbers stored in a string variable?
      $str = "18,03,48,23" MsgBox(0,"test",$str) I would like it to display "03,18,23,48"
    • nooneclose
      By nooneclose
      My program has to first search for names in Column D that do not match up with column C. I got that search to work using arrays. It was slow and I could not figure out how to delete them so I just manually put coded the names that do not belong. I found their cell location but I do not know how to store that location and delete it.
      This is what I have so far.
      Local $NameToDelete1[6]  = _Excel_RangeFind($OpenWorkbook, "Smith, Bill") _ArrayDisplay($NameToDelete1, "Excel UDF: _Excel_RangeFind Example 1", "", 0, "|", "Sheet|Name|Cell|Value|Formula|Comment") _Excel_RangeDelete($OpenWorkbook.ActiveSheet, $NameToDelete1[2], $xlShiftUp)  
      Please help, I wanted to have this program done yesterday but I did not see this problem until yesterday. 
×