Jump to content
Sign in to follow this  

Acquiring a string from the right side of a symbol in a text file

Recommended Posts


The script below will read the testfile.txt, that has the following contents:


It will then proceed to strip any text to the left of the equal sign including the equal sign i.e. so it shows up as c:\windows, which is the expected behavior. Alternately, I would like to strip any text that is right of the equal sign including the equal sign instead. Whether I change the "StringTrimLeft" to "StringTrimRight" or change the "1"/"-1" entries on the "$LeftofEqual" variable or both, I don't get the hopeful results of it showing up as path

I can't do any specific trim numbers as that will vary, so that's why I am acquiring the number of characters leading up to the equal sign, but I can't seem to reverse it where it acquires the number of characters from the right side of it instead. The full code is below:

$readline = FileReadLine("testfile.txt",1)
$LeftofEqual=StringInStr($readline, "=", 1, -1)
$result = StringTrimLeft ($readline,$LeftofEqual)

Thanks in advance for any assistance that can be provided.

Edited by TheCrimsonCrusader

Share this post

Link to post
Share on other sites

Here you go:

$readline = FileReadLine("testfile.txt",1)
$LeftofEqual=StringInStr($readline, "=", 1, -1)
$result = StringTrimLeft ($readline,$LeftofEqual)
$result = StringTrimRight($readline, StringLen($readline)-$LeftofEqual+1)

To strip the right part - you need to consider string length.

Edited by enaiman

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post

Link to post
Share on other sites


Or you can use a SRE like this to split on the = sign directly: :)

$sText = "path=c:\windows"

$sLeft  = StringRegExpReplace($sText, "(.*)=(.*)", "$1")
$sRight = StringRegExpReplace($sText, "(.*)=(.*)", "$2")

MsgBox(0, "Result", $sLeft & @CRLF & $sRight)

SRE explanation:

(.*)    - Capture any number of characters
=       - Do not capture an = sign
(.*)    - Capture any number of characters

$1      - Replace with first captured group
$2      - Replace with second captured group

Please ask if anything is unclear. :mellow:


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:


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


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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...