Jump to content

String Formate


Recommended Posts

Whoa okay *Ive learned that I personally hate string stuff cause its so complicated sometimes. But ive been working on learning it.

But my current issue is I have a edit box inside of gui that records a bunch of data entered by the user.

like this

$Edit1 = GUICtrlCreateEdit("", 8, 24, 609, 249)
GUICtrlSetData(-1, StringFormat("Enter the URL"&Chr(39)&"s here.\r\n\r\nExample:\r\nhttp://pennybutler.com/plugin-reviews/20-wordpress-plugins-membership/\r\nhttp://www.viperchill.com/internet-marketing-toolbox/\r\nhttp://www.nickycakes.com/2008-top-10-worst-make-money-online-sites/"))

so it also shows the user a example witch they will be entered into the feild like this

URL1
URL2
URL3

but now when im writing my code I want to be able to say if $Edit1[0] then

or if $Edit1[1] then

So it will divide each url into $Edit1[1 or 2 or 3 or 4 or 5......]

How do I do this.

I was trying to use this StringFormat ( "format control", var1 [, ... var32] ) but cant get it to work.

All help is greatly appreciated

Link to comment
Share on other sites

Kinda mystified about what you like to do. But your StringFormat() use definitely needs some work.

As it looks a the moment your trying to use it to only add linebreaks to some URL's

Personally I would just do something like this.

Dim Const $NL = @CRLF
Dim $sVar = 'http://pennybutler.com/plugin-reviews/20-wordpress-plugins-membership/' & @CRLF
$sVar &= 'http://www.viperchill.com/internet-marketing-toolbox/' & $NL & 'http://www.nickycakes.com/2008-top-10-worst-make-money-online-sites/'

StringFormat() example

Dim $format = 'date=(% 4d/%02d/%02d)'
ConsoleWrite(StringFormat($format, 123, 5, 9) & @CRLF) ;; -> "date=( 123/05/09)"

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

I think this might better explain what im tring to do.

$Url = StringRegExp($Edit1, "(?m)");
    msgbox (1, "Text", $Url);
    msgbox (1, "Test0", $Url[0]);
    msgbox (1, "Text1", $Url[1]);

Another words I want it to divide $Edit1 into subvariables of $URL by each linebreak

I think that is a better way to explain what im going for

Link to comment
Share on other sites

I think this might better explain what im tring to do.

$Url = StringRegExp($Edit1, "(?m)");
    msgbox (1, "Text", $Url);
    msgbox (1, "Test0", $Url[0]);
    msgbox (1, "Text1", $Url[1]);

Another words I want it to divide $Edit1 into subvariables of $URL by each linebreak

I think that is a better way to explain what im going for

Would this work?

$URL=StringSplit($Edit1,"\n")

There's no place like ~/

Link to comment
Share on other sites

Okay I tried to implament it but still dosnt work dont quite know why im assumeing cause the edit feild is in abother gui screen

here is my full code

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("King Ping Software - Setup", 625, 324, 192, 124)
$Edit1 = GUICtrlCreateEdit("", 8, 24, 609, 249)
GUICtrlSetData(-1, StringFormat("Enter the URL"&Chr(39)&"s to ping here.\r\n\r\nExample:\r\nhttp://pennybutler.com/plugin-reviews/20-wordpress-plugins-membership/\r\nhttp://www.viperchill.com/internet-marketing-toolbox/\r\nhttp://www.nickycakes.com/2008-top-10-worst-make-money-online-sites/"))
$Label1 = GUICtrlCreateLabel("List of Url's To Ping", 8, 8, 95, 17)
$Start = GUICtrlCreateButton("Start", 544, 288, 75, 25, $WS_GROUP)
$Keyword = GUICtrlCreateInput("Enter Your Keyword Here", 8, 288, 529, 21)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $Start
    
    GuiSetState(@SW_HIDE);
    $Form2 = GUICreate("King Ping Software - Progress", 287, 137, 192, 124)
    $Label1 = GUICtrlCreateLabel("Completed Number", 8, 16, 121, 20)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    $Progress1 = GUICtrlCreateProgress(9, 72, 262, 17)
    $Label2 = GUICtrlCreateLabel("Total Number", 192, 16, 86, 20)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    $AlreadySent = GUICtrlCreateLabel("0", 56, 40, 10, 17)
    $TotalNumber = GUICtrlCreateLabel("0", 232, 40, 10, 17)
    $Stop = GUICtrlCreateButton("Cancel", 112, 104, 75, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    $Count = "0"
    $URL=StringSplit($Edit1, "|", 1)
    msgbox (1, "Test0", $Url[0]);
    msgbox (1, "Text1", $Url[1]);



        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Edited by Medic873
Link to comment
Share on other sites

Dim $sInput = '' & _
        'http://pennybutler.com/plugin-reviews/20-wordpress-plugins-membership/' & @CRLF & _
        'http://www.viperchill.com/internet-marketing-toolbox/' & @CRLF & _
        'https://www.nickycakes.com/2008-top-10-worst-make-money-online-sites/'
MsgBox(0, '$sInput', '$sInput:' & @CRLF & $sInput)

$sInput = StringStripCR($sInput) ;; get rid of [@cr] or [\r] parts.
Dim $aOutput = StringRegExp($sInput, 'http[s]?.*', 3) ;; split on [\n] part.

Dim $sOutput = '[0]=' & $aOutput[0] & @CRLF & '[1]=' & $aOutput[1] & @CRLF & '[2]=' & $aOutput[2]
MsgBox(0, '$sOutput', $sOutput)

---

Erm ... I see not much has changed in your StringFormat() use.

:mellow:

Edited by iEvKI3gv9Wrkd41u

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

Okay I tried to implament it but still dosnt work dont quite know why im assumeing cause the edit feild is in abother gui screen

here is my full code

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("King Ping Software - Setup", 625, 324, 192, 124)
$Edit1 = GUICtrlCreateEdit("", 8, 24, 609, 249)
GUICtrlSetData(-1, StringFormat("Enter the URL"&Chr(39)&"s to ping here.\r\n\r\nExample:\r\nhttp://pennybutler.com/plugin-reviews/20-wordpress-plugins-membership/\r\nhttp://www.viperchill.com/internet-marketing-toolbox/\r\nhttp://www.nickycakes.com/2008-top-10-worst-make-money-online-sites/"))
$Label1 = GUICtrlCreateLabel("List of Url's To Ping", 8, 8, 95, 17)
$Start = GUICtrlCreateButton("Start", 544, 288, 75, 25, $WS_GROUP)
$Keyword = GUICtrlCreateInput("Enter Your Keyword Here", 8, 288, 529, 21)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $Start
    
    GuiSetState(@SW_HIDE);
    $Form2 = GUICreate("King Ping Software - Progress", 287, 137, 192, 124)
    $Label1 = GUICtrlCreateLabel("Completed Number", 8, 16, 121, 20)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    $Progress1 = GUICtrlCreateProgress(9, 72, 262, 17)
    $Label2 = GUICtrlCreateLabel("Total Number", 192, 16, 86, 20)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    $AlreadySent = GUICtrlCreateLabel("0", 56, 40, 10, 17)
    $TotalNumber = GUICtrlCreateLabel("0", 232, 40, 10, 17)
    $Stop = GUICtrlCreateButton("Cancel", 112, 104, 75, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    $Count = "0"
    $URL=StringSplit($Edit1, "|", 1)
    msgbox (1, "Test0", $Url[0]);
    msgbox (1, "Text1", $Url[1]);



        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Edit1 does not store the text within the edit, only the handle to

the edit gui control. You have to read the handle to get the text.

Also, they strings are split by CRLF's so this code works:

$URL=StringSplit(GUICtrlRead($Edit1), @crlf, 1)

URL[0] Does not contain the first string, it contains the number

of strings that were split, so in your case, it should read 3

msgbox (1, "Test0", $Url[1]);
msgbox (1, "Text1", $Url[2]);
msgbox (1, "Text1", $Url[3]);

There's no place like ~/

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