Jump to content

Search for mumbers in txt


Recommended Posts

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

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

here :

text text text 3+7? (Eventyaly More Text) - example 1

Text Text Text 15-10? (eventualy more text) - exsample 2

Text Text Text 18x3? (eventualy more text) -exsample 3

it's not the same every time and its allays 1 line

Link to comment
Share on other sites

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)
Next

I did not implement % and the file write code. What is %? -> implemented

Br,

UEZ

Edited 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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

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 by saio
Link to comment
Share on other sites

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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