Jump to content

Help StringTrimLeft


TheWebz
 Share

Recommended Posts

I wanted to delete a string until a certain character. Does anyone know how?

I am using StringTrimRigt

EX:

Before-->"AutoIt#Script"

After--->"AutoIt#"

The problem is that i need something that work in every case!!

If someone knows please reply.

Edited by TheWebz
Link to comment
Share on other sites

  • Developers

You are again somewhat vague here. Do you wan to trim everything after #?

Something like this would work:

$string=StringLeft($string,StringInStr($String,"#"))

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Moderators

TheWebz,

Take a look at StringSplit - much easier to get what you want: ;)

$sOld = "AutoIt#Script"

$sSplit = StringSplit($sOld, "#")

MsgBox(0, "Result", $sSplit[1] & "#")

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

As you can see in the attatched file when i do _ArrayDisplay it shows up with a window. It has two colums, and when i select an item and click copy and then i paste it in notepad it separate the two colums strings with a "|".

Is it possible to change that character?

post-77101-0-95414100-1356738417_thumb.j

Edited by TheWebz
Link to comment
Share on other sites

TheWebz,

Yes, but it is not neccessary. Look at the example M23 gave you. You can assign whatever you want to a variable for whatever use you need.

kylomas

edit: you may also want to take a look at the Wiki's on arrays

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Look, this is my code:

;BIBLIOTECAS A INCLUIR--------------
#include
#Include
#Include
#include
#include
#include
#include
#include
;FIM DE BIBLIOTECAS A INCLUIR-------

;VISUAL-----------------------------------------------------------
$form = GUICreate( "test", 500, 500 )
$Button1 = GUICtrlCreateButton("Search Music", 112, 424, 281, 49)
$Input1 = GUICtrlCreateInput("Input1", 128, 128, 249, 21)
$Button2 = GUICtrlCreateButton("Download", 200, 160, 99, 41)
GUICtrlSetState( $Button2,$GUI_DISABLE )
GUICtrlSetState( $Input1,$GUI_DISABLE )
GUISetState( @SW_SHOW )
;FIM VISUAL-------------------------------------------------------


;FUNCAO CASO GUI SEJA FECHADA------------
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
;FIM FUNCAO CASO GUI SEJA FECHADA--------


;CASO BOTAO 1---------------------------------------------------------------------------------------------------------------------------------
Case $Button1
Global $sSearchingFor = InputBox( "Musica", "Escreva aqui em baixo o nome da música." )
; Specify the reguest:
Global $sURL = "[url="http://mp3skull.com/mp3/"]http://mp3skull.com/mp3/"[/url] & StringReplace( $sSearchingFor, " ", "_" ) & ".html"
;$sURL = "[url="http://mp3skull.com/mp3/barclay_james_harvest.html"]http://mp3skull.com/mp3/barclay_james_harvest.html"[/url]

ProgressOn( "Searching..", "Working..", "Searching for " & $sSearchingFor & " ..." )
ProgressSet( 30 )
sleep(1000)
Global $sRes = _INetGetSource($sURL)

ProgressSet( 100, "Done!" )
Sleep(3000)
ProgressOff()
$aRes = _StringBetween($sRes,'"font-size:15px;">','rel="nofollow" target="_blank"') ;if title and Downloadlink is needed this line
Dim $aRes1[UBound($aRes)][2]
For $i = 0 to UBound($aRes) -1
$sTitle = _StringBetween($aRes[$i],'[b]','[/b]')
If IsArray($sTitle) Then $aRes1[$i][0]=$sTitle[0]
$sDL_URL = _StringBetween($aRes[$i],'

I think you didn't understand.

This isn't an insult maybe im wrong.

Reply pls.

Edited by TheWebz
Link to comment
Share on other sites

Func _ArrayShow(Const ByRef $aArray, $sDelim1 = "|", $sDelim2 =@CRLF, $fToConsole = True, $fToClip = False, $iStart = 0, $iEnd = 0, $sDelim3 = @CRLF)
Local $iDimensions = UBound($aArray, 0)
Local $iBound = UBound($aArray, 1) - 1
if $iEnd=0 then $iEnd=$iBound
If $iEnd < $iBound Then $iBound = $iEnd
IF $iStart>$iBound then return
Local $sMSG
Switch $iDimensions
Case 0
ConsoleWrite($aArray)
Case 1
For $i = $iStart To $iBound
$sMSG &= $aArray[$i] & $sDelim1
Next
Case 2

For $i1 = $iStart To $iBound
For $i2 = 0 To UBound($aArray, 2)-1
$sMSG &= $aArray[$i1][$i2]

$sMSG &= $sDelim1
Next
$sMSG &= $sDelim2
Next
Case 3

For $i1 = $iStart To $iBound
For $i2 = 0 To UBound($aArray, 2)-1
For $i3 = 0 To UBound($aArray, 3)-1
$sMSG &= $aArray[$i1][$i2][$i3]
$sMSG &= $sDelim1
Next
$sMSG &= $sDelim2
Next
$sMSG &= $sDelim3
Next
EndSwitch
if $fToConsole=True then ConsoleWrite($sMSG)
if $fToClip then ClipPut($sMSG)
EndFunc ;==>_arrayout

Edited by DicatoroftheUSA
Link to comment
Share on other sites

Ah... If i understand you right, you want to choose an other seperator character for the listview from _ArrayDisplay.

The 5th parameter of this function will help you:

;===============================================================================
; Example 2 (using a manually-defined array)
;===============================================================================
Local $avArray[10]

$avArray[0] = "JPM"
$avArray[1] = "Holger"
$avArray[2] = "Jon"
$avArray[3] = "Larry"
$avArray[4] = "Jeremy"
$avArray[5] = "Valik"
$avArray[6] = "Cyberslug"
$avArray[7] = "Nutster"
$avArray[8] = "JdeB"
$avArray[9] = "Tylo"

_ArrayDisplay($avArray, "$avArray set manually 1D", Default, Default, "@")

... will use "@" as seperator character.

chess

Edited by chesstiger
Link to comment
Share on other sites

What's wrong???

;BIBLIOTECAS A INCLUIR--------------
#include 
#Include 
#Include 
#include 
#include 
#include 
#include 
#include 
;FIM DE BIBLIOTECAS A INCLUIR-------

;VISUAL-----------------------------------------------------------
$form = GUICreate( "test", 500, 500 )
$Button1 = GUICtrlCreateButton("Search Music", 112, 424, 281, 49)
$Input1 = GUICtrlCreateInput("Input1", 128, 128, 249, 21)
$Button2 = GUICtrlCreateButton("Download", 200, 160, 99, 41)
GUICtrlSetState( $Button2,$GUI_DISABLE )
GUICtrlSetState( $Input1,$GUI_DISABLE )
GUISetState( @SW_SHOW )
;FIM VISUAL-------------------------------------------------------


;FUNCAO CASO GUI SEJA FECHADA------------
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
;FIM FUNCAO CASO GUI SEJA FECHADA--------


;CASO BOTAO 1---------------------------------------------------------------------------------------------------------------------------------
Case $Button1
Global $sSearchingFor = InputBox( "Musica", "Escreva aqui em baixo o nome da música." )
; Specify the reguest:
Global $sURL = "http://mp3skull.com/mp3/" & StringReplace( $sSearchingFor, " ", "_" ) & ".html"
;$sURL = "http://mp3skull.com/mp3/barclay_james_harvest.html"

ProgressOn( "Searching..", "Working..", "Searching for " & $sSearchingFor & " ..." )
ProgressSet( 30 )
sleep(1000)
Global $sRes = _INetGetSource($sURL)

ProgressSet( 100, "Done!" )
Sleep(3000)
ProgressOff()
$aRes = _StringBetween($sRes,'"font-size:15px;">','rel="nofollow" target="_blank"') ;if title and Downloadlink is needed this line
Dim $aRes1[UBound($aRes)][2]
For $i = 0 to UBound($aRes) -1
$sTitle = _StringBetween($aRes[$i],'[b]','[/b]')
If IsArray($sTitle) Then $aRes1[$i][0]=$sTitle[0]
$sDL_URL = _StringBetween($aRes[$i],'<a data-cke-saved-href="','" href="','" ')="" if="" isarray($sdl_url)="" then="" $ares1[$i][1]="$sDL_URL[0]<br">Next
_ArrayDisplay($aRes1, "", Default, Default, "¨")
GUICtrlSetState( $Button2,$GUI_ENABLE )
GUICtrlSetState( $Input1,$GUI_ENABLE )
;FIM DO CASO BOTAO 1--------------------------------------------------------------------------------------------------------------------------

Case $Button2
$RInput1 = GUICtrlRead( $Input1 )

$link = StringLeft($RInput1,StringInStr($RInput1,"¨"))
MsgBox( 64, "TESTE", "" & $link )

EndSwitch
WEnd
Link to comment
Share on other sites

If you want to use a different separater that will get copied to the clipboard when you use the "Copy Selected" button in _ArrayDisplay, you need to write it like this.

#include <Array.au3>
;===============================================================================
; Example 4 (a 2D array)
;===============================================================================
Local $avArray[2][5] = [["JPM", "Holger", "Jon", "Larry", "Jeremy"],["Valik", "Cyberslug", "Nutster", "JdeB", "Tylo"]]
_ArrayDisplay($avArray, "$avArray as a 2D array", -1, 0, "@", "@") ; you need to supply the alternate separator character and the replacement

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

TheWebz,

When posting autoit code and using the tags [autoit][/autoit], toggle the editing mode (button next to the eraser top left) to basic and then you shouldn't have the include files being stripped.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

If you want to use a different separater that will get copied to the clipboard when you use the "Copy Selected" button in _ArrayDisplay, you need to write it like this.

#include <Array.au3>
;===============================================================================
; Example 4 (a 2D array)
;===============================================================================
Local $avArray[2][5] = [["JPM", "Holger", "Jon", "Larry", "Jeremy"],["Valik", "Cyberslug", "Nutster", "JdeB", "Tylo"]]
_ArrayDisplay($avArray, "$avArray as a 2D array", -1, 0, "@", "@") ; you need to supply the alternate separator character and the replacement

Referring to the comment, " ; you need to supply the alternate separator character and the replacement".

The $sReplace parameter is never used. It is useless in the _ArrayDisplay function.

Looking at the logical flow of this function, at the "; Check the separator to make sure it's not used literally in the array" routine, if the separator exists in any of the elements of the array, the separator is changed.

So after this routine the separator does not exist in any of the elements of the array.

Further down the _ArrayDisplay function, there is the one liner "; Add to text array" routine. This StringReplace function replaces all occurrences of the separator in the elements of the array with the contents of the $sReplace parameter.

Because the separator will never exist in any of the elements of the array, the contents of $sReplace parameter will never be used as a replacement character.

The $sSeparator parameter in the _ArrayDisplay() function can be used for displaying a

string at the beginning of each element in the array. Could be handy. See "Sir Col 0" in example.

;===============================================================================
; Example 2 (using a manually-defined array)
;===============================================================================
#include <Array.au3>
Local $avArray[10]

$avArray[0] = "JPM"
$avArray[1] = "Holger"
$avArray[2] = "Jon"
$avArray[3] = "Larry"
$avArray[4] = "Jeremy"
$avArray[5] = "Valik"
$avArray[6] = "Cyberslug"
$avArray[7] = "Nutster"
$avArray[8] = "JdeB"
$avArray[9] = "Tylo"

; Separates header on each coma, and the array display looks good.
_ArrayDisplay($avArray, "$sSeparator =,", -1, 0, ",", "", "Row,Col1,Col2|A|B")

; Because the $sSeparator, "r", exists at least once in any of the elements, the $sSeparator automatically changes.
; And when the new separator does not appear in the header string the second column is not created.
_ArrayDisplay($avArray, "$sSeparator =r", -1, 0, "r", "", "Row,rCol1,rCol2|A|B")

; Adds "Sir " to the beginning of each element in the array, and, to the header "Sir Col 0".
; ("q" does not exist in any of the elements of the array)
_ArrayDisplay($avArray, "$sSeparator =qSir ", -1, 0, "qSir ")

I noticed in the Preview Post the text, "; Because the $sSeparator, "r", exists at least once in any of the elements...." the word "least" was automatically changed to "Least" - weird.

Link to comment
Share on other sites

Did you fix _ArrayDisplay or post in Trac?

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

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