MyEarth Posted May 1, 2013 Posted May 1, 2013 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
PhoenixXL Posted May 1, 2013 Posted May 1, 2013 (edited) 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 May 1, 2013 by PhoenixXL guiltyking 1 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.
water Posted May 1, 2013 Posted May 1, 2013 "After a character" means after the first space or another character? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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
MyEarth Posted May 1, 2013 Author Posted May 1, 2013 (edited) After the character, so after the first &:Atext & PAnotherU & Dontoer_HKSCSor leave as it as if don't have a &Normal string without commercial eI'll test the script of PhoneixXLEDIT: 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 May 1, 2013 by MyEarth
water Posted May 1, 2013 Posted May 1, 2013 $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 2024-07-28 - Version 1.6.3.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 (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
MyEarth Posted May 1, 2013 Author Posted May 1, 2013 (edited) Water, did you test it? Try to see the third string of the array ( so the string without & )MsgBox(0,0,$aArray[3])Result = NothingInsted the result must be: Normal string without commercial e Edited May 1, 2013 by MyEarth
water Posted May 1, 2013 Posted May 1, 2013 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 2024-07-28 - Version 1.6.3.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 (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
MyEarth Posted May 1, 2013 Author Posted May 1, 2013 And why you are on Ubuntu? Yes, if i check the string have or not have the & and the do the Func is the right solution, thanks to both
water Posted May 1, 2013 Posted May 1, 2013 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 2024-07-28 - Version 1.6.3.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 (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
mikell Posted May 1, 2013 Posted May 1, 2013 (edited) 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 May 1, 2013 by mikell
PhoenixXL Posted May 1, 2013 Posted May 1, 2013 (edited) 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 May 1, 2013 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.
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