saio Posted May 12, 2012 Posted May 12, 2012 I want to find a numbers in a txt file containing: Some Text Number 1 +/-/x/%/ number 2 (eventualy +/-/x/% number 3) and calculate them then whrit them in to Text file2 txt how do i do that???
Moderators Melba23 Posted May 12, 2012 Moderators Posted May 12, 2012 saio, Can you post an example of the text file from which you need to extract the numbers - it is always easier when we have something to work on. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
saio Posted May 12, 2012 Author Posted May 12, 2012 (edited) that is what it looks like i have input 3 exsamples inside the idea is to get the numbers and than calculate the score and tipe it into text file named Text2.txtNew Text Document (3).txt Edited May 12, 2012 by saio
Moderators Melba23 Posted May 12, 2012 Moderators Posted May 12, 2012 saio, Please help us to help you - are these numbers integers? Decimals? Fractions? I should not be difficult to write an RegEx to extract them, but we need to see exactly how the line is written to define the pattern. So please post a line so that we can see what we are dealing with. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
saio Posted May 12, 2012 Author Posted May 12, 2012 saio,Please help us to help you - are these numbers integers? Decimals? Fractions? I should not be difficult to write an RegEx to extract them, but we need to see exactly how the line is written to define the pattern. So please post a line so that we can see what we are dealing with. M23here :text text text 3+7? (Eventyaly More Text) - example 1Text Text Text 15-10? (eventualy more text) - exsample 2Text Text Text 18x3? (eventualy more text) -exsample 3it's not the same every time and its allays 1 line
UEZ Posted May 12, 2012 Posted May 12, 2012 (edited) Try this:#include <array.au3> $text = _ "text text text 3+7? or 2x3 (Eventyaly More Text) - example 1" & @CRLF & _ "Text Text Text 15-10x3? (eventualy more text) - example 2" & @CRLF & _ "Text Text Text 18x3+1? (eventualy more text) -example 3" & @CRLF & _ "Text Text Text 18%3+1? (eventualy more text) -example 4" $aResult = StringRegExp($text, "s[d+|+|-|x|%]+d+", 3) For $i = 0 To UBound($aResult) - 1 $aResult[$i] = StringReplace($aResult[$i], "x", "*") $aResult[$i] = StringReplace($aResult[$i], "%", "/") ConsoleWrite($aResult[$i] & "=" & Execute($aResult[$i]) & @CRLF) NextI did not implement % and the file write code. What is %? -> implementedBr,UEZ Edited May 12, 2012 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
saio Posted May 12, 2012 Author Posted May 12, 2012 (edited) the numbers and the text is diferent evry thime and the % is / 10/5 =2 &18x3+1? &CRLF &_ unterminated string .... allso that $aResult = StringRegExp($text, "s[d+|+|-|x|%]+d+", 3) For $i = 0 To UBound($aResult) - 1 $aResult[$i] = StringReplace($aResult[$i], "x", "*") $aResult[$i] = StringReplace($aResult[$i], "%", "/") ConsoleWrite($aResult[$i] & "=" & Execute($aResult[$i]) & @CRLF) Next gives result 1 to 45+8 shud it be something like For $i = 0 To UBound(99999)...... Allso tryed : $text4 = ClipGet () $aResult = StringRegExp($text4, "s[d+|+|-|x|%]+d+", 3) For $i = 0 To UBound($aResult) - 99999 $aResult[$i] = StringReplace($aResult[$i], "x", "*") $aResult[$i] = StringReplace($aResult[$i], "%", "/") ConsoleWrite($aResult[$i] & "=" & Execute($aResult[$i])) Next and it still gives 1 .... any help? I copy to clickboard: 45+8? is the ? any problem and how to filter it? becose it coud be 45+63? or less simbols 6/8.... Edited May 12, 2012 by saio
UEZ Posted May 14, 2012 Posted May 14, 2012 Can you provide a real text where we can see what the problem is? Because 45+8 in a string will be calculated properly! Otherwise try this here: $text = ClipGet() ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $text = ' & $text & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console $aResult = StringRegExp($text, "[d+|+|-|x|%]+d+", 3) For $i = 0 To UBound($aResult) - 1 $aResult[$i] = StringReplace($aResult[$i], "x", "*") $aResult[$i] = StringReplace($aResult[$i], "%", "/") ConsoleWrite($aResult[$i] & "=" & Execute($aResult[$i]) & @CRLF) Next Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
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