Jump to content
Sign in to follow this  
MyEarth

Remove string after x

Recommended Posts

MyEarth

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

Share this post


Link to post
Share on other sites
PhoenixXL

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

Share this post


Link to post
Share on other sites
water

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


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
MyEarth

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

Share this post


Link to post
Share on other sites
water

$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 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
MyEarth

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

Share this post


Link to post
Share on other sites
water

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 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
MyEarth

And why you are on Ubuntu? :D

Yes, if i check the string have or not have the & and the do the Func is the right solution, thanks to both ;)

Share this post


Link to post
Share on other sites
water

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 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
mikell

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

Share this post


Link to post
Share on other sites
PhoenixXL

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.

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  

  • Similar Content

    • nooneclose
      By nooneclose
      I need help turning this string "20180913221626" into a formatted time string.
      I need to go from this: 20180913221626
      to this: 09/13/2018 10:16 PM
      I do not always know what the date will be so I can not just use a variable I need to actually convert/format. 
      I did see an older post in the forms that was basically the same question only the other guy did not post the working code and I can not figure out how to use _AD_GetObjectProperties properly to get what I want. 
      As always any help would be appreciated. 
      Here is the code I use to find the date, but it always gives me the unformatted version. 
      ;retrieve the items object $oItem = $oOutlook.Session.GetItemFromID($aItems[1][0], Default) $oItem.GetInspector $eSentOn = $oItem.SentOn ; When was the email sent? MsgBox("", "Sent On of the email", $eSentOn) ;******************************************************************************* ; Formats the date and time from the email ;******************************************************************************* ;Local $fDatenTime = _DateTimeFormat($eSentOn, 1) ;MsgBox("", "Formatted email time", $fDatenTime) $aProperties = _AD_GetObjectProperties($eSentOn) _ArrayDisplay($aProperties, "Did the conversion work?")  
    • Miliardsto
      By Miliardsto
      I got that func
      Func makeHelpImgGUI($title,$width,$height,$img) $img = GUICtrlCreatePic("",20,40,$width,$height) _ResourceSetImageToCtrl($img, "HERE") EndFunc and I call this func like that
      makeHelpImgGUI("Image",1190, 800,$SETTINGS_JPG)  
      so what is the problem in the parameter where is - "HERE" I need value of img but passed as string
      so $img = $SETTINGS_JPG and how make it "SETTINGS_JPG"
       
      I tried something like that but not work
      Func makeHelpImgGUI($title,$width,$height,$img) $name_str = String($img) $name_str = StringTrimLeft ($name_str, 1 ) $img = GUICtrlCreatePic("",20,40,$width,$height) _ResourceSetImageToCtrl($img, $name_str) EndFunc  
    • liagason
      By liagason
      Hello everyone,
      How can I display in ascending  sequence some numbers stored in a string variable?
      $str = "18,03,48,23" MsgBox(0,"test",$str) I would like it to display "03,18,23,48"
    • Rskm
      By Rskm
      Hi, I have the following line in a text file 'input.txt'. I know the line number - say '6'. I wish to replace the text 'WWW' in the below line with a random number (I can generate that with random()).
      WERIS  WWWJP   3.83  8.330  1.000                1097.RAXX 
      The WWW is a 3 digit integer (could be any number between 0 to 999), I can use stringtrimleft and get the numerical value of WWW in this file
      so, basically, I know the string to replace (ie; WWW stored in a variable), I know the line number to work on and the file location/name and the replacement variable (through random()). My requirement is to fill that 3 spaces with my random number (which Is a integer between 1 and 999)
      please put ur suggestions
       
    • nacerbaaziz
      By nacerbaaziz
      Hello Members of this best Forum
      i have a question please
      for example if i have a long string
      and i want to extract a text between two tag
      what i can do to make that?
      note :
      i know that there is a
      StringRegExp function
      it's do that work
      but it result is be as an array
      i want the result to be a string
      is there any function on autoit can do that?
      Thanks in advance.
×