Jump to content

Remove string after x


Recommended Posts

Hi community the title is explicative, hqo to delete a string after a character?

This is what i have do:

$aArray[4] = [4, 'Atext & PAnotherU & Dontoer_HKSCS', 'Fatang & FatangDhe & GungRuh & GangsuhChe', 'Normal string without commercial e']
For $x = 1 To $aArray[4] - 1
$aArray[$x] = ; ???????????????
Next
; Result must be:
; Atext, Fatang, Normal string without e-commercial

Any help is appreciated

Link to comment
Share on other sites

Func RemoveStringFrom($String, $S_From, $Case_Sense = 0, $iOccurance = 1)
Return StringLeft($String, StringInStr($String, $S_From, $Case_Sense, $iOccurance) - 1) ;Check the helfile for more info about these functions
EndFunc ;==>RemoveStringAfter

MsgBox(0, 0, RemoveStringFrom("Atext & PAnotherU & Dontoer_HKSCS", " "))
MsgBox(0, 0, RemoveStringFrom("Fatang & FatangDhe & GungRuh & GangsuhChe", " "))
MsgBox(0, 0, RemoveStringFrom("Normal string without commercial e", " ", 0, -1))
Hope it helps

Ask if any queries

Regards :)

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

"After a character" means after the first space or another character?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

After the character, so after the first &:

Atext & PAnotherU & Dontoer_HKSCS

or leave as it as if don't have a &

Normal string without commercial e

I'll test the script of PhoneixXL

EDIT: PhoneixXL i can't use your script. I need to pass the same function on an array so i can't change parameter, i don't know if the string have or don't have a &

Edited by MyEarth
Link to comment
Share on other sites

$aArray[4] = [3, 'Atext & PAnotherU & Dontoer_HKSCS', 'Fatang & FatangDhe & GungRuh & GangsuhChe', 'Normal string without commercial e']
For $x = 1 To $aArray[0]
    $aArray[$x] = RemoveStringFrom($aArray[$x], "&"))
Next

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Water, did you test it? :D

Try to see the third string of the array ( so the string without & )

MsgBox(0,0,$aArray[3])

Result = Nothing

Insted the result must be: Normal string without commercial e

Edited by MyEarth
Link to comment
Share on other sites

Test? No! Not possible on Ubuntu ;)

Modify the function PhoenixXL provided:

Func RemoveStringFrom($String, $S_From, $Case_Sense = 0, $iOccurance = 1)
    Local $iPos = StringInStr($String, $S_From, $Case_Sense, $iOccurance)
    If $iPos = 0 Then Return $String
    Return StringLeft($String, $iPos - 1) ;Check the helfile for more info about these functions
EndFunc ;==>RemoveStringAfter

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

At home my main system is Ubuntu. Windows just runs in a virutal machine. I was just too lazy to start it up.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Why not something like this ?

#Include <Array.au3>

Dim $aArray[4] = [4, 'Atext & PAnotherU & Dontoer_HKSCS', 'Fatang & FatangDhe & GungRuh & GangsuhChe', 'Normal string without commercial e']

$char = "&"
For $x = 1 To 3
$aArray[$x] = StringRegExpReplace($aArray[$x], '(.+?)(?:\h*' & $char & ').+', "$1")
Next
_ArrayDisplay($aArray)
Edited by mikell
Link to comment
Share on other sites

Why not something like this ?

Because both would serve the same purpose with the same simplicity, but with the regex the time consumption would be obviously more.

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

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

×
×
  • Create New...