Sign in to follow this  
Followers 0
Khryus

What's wrong with this?

6 posts in this topic

#1 ·  Posted (edited)

So, I made a function which has to break a line when it encounters a special character.

Func breakLine($string_to_break, $character_to_break)
    Local $stb=StringSplit($string_to_break, $character_to_break)
    Return $stb[1]&@CRLF&$stb[2]
EndFunc

And I am using it to modify a mask.

$desctable_mask="ACCID#@ACCNAME@#@@"
Local $sInfo[3]
$sInfo[0]="ID"
$sInfo[1]="DB"
$sInfo[2]="SC"
$patch=breakLine(StringReplace(StringReplace($desctable_mask, "ACCID", $sInfo[0]), "ACCNAME", $sInfo[1]), "@")

It actually breaks the line, however, this is what it should display on the output:

ID#
SC
#

And this is what it's actually displaying.

ID#
SC

How is that so?

What I am trying to do:

Break the line when a @ occurs

Replace "ACCID" with $sInfo[0]

Replace "ACCNAME" with $sInfo[1]

Display result in the output.

And no, ACCID and ACCNAME aren't "Account ID" and "Account Name", they're actually "Accessory ID" and "Accesory Name".

Thanks in advance ;)

Edited by megablox

"The story of a blade is linked in Blood." 

―Yasuo

 

Share this post


Link to post
Share on other sites



Try this, your second "#" is in another element of the array. So you have to send that back as well in the Return statement.

$desctable_mask = "[email="ACCID#@ACCNAME"]ACCID#@ACCNAME[/email]@#@@"
Local $sInfo[3]
$sInfo[0] = "ID"
$sInfo[1] = "DB"
$sInfo[2] = "SC"
$patch = breakLine(StringReplace(StringReplace($desctable_mask, "ACCID", $sInfo[0]), "ACCNAME", $sInfo[2]), "@")
Func breakLine($string_to_break, $character_to_break)
    Local $stb = StringSplit($string_to_break, $character_to_break)
    Return $stb[1] & @CRLF & $stb[2] & @CRLF & $stb[3] ; I'm not sure if you need another @CRLF at the end of the Return line as well
EndFunc   ;==>breakLine

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

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Oh yeah, thanks ! That worked ;)

By the way, would this automatically return all the items in the array?

Func breakLine($string_to_break, $character_to_break)
    Local $stb = StringSplit($string_to_break, $character_to_break)
    Local $mrg = ""
    For $i=1 To $stb[0] Step 1
        $mrg=$stb[$i]&@CRLF
    Next
    Return $mrg;$stb[1] & @CRLF & $stb[2] & @CRLF & $stb[3]
EndFunc   ;==>breakLine
Edited by megablox

"The story of a blade is linked in Blood." 

―Yasuo

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Woops

instead of

$mrg=$stb[$i]&@CRLF

I changed that line to

$mrg=$mrg&$stb[$i]&@CRLF

Then I tested it, but it a few more returns.

ID#
SC
#
<return here>
<return here>
Edited by megablox

"The story of a blade is linked in Blood." 

―Yasuo

 

Share this post


Link to post
Share on other sites

You're going to get the extra blank lines because the test string ends in "@@" and the string split will split there, which creates 2 empty elements.


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

Share this post


Link to post
Share on other sites

Oh yeah, that's right.Thank you ;)


"The story of a blade is linked in Blood." 

―Yasuo

 

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  
Followers 0