Source language: Translate to:

String replace on certain lines

General questions about NeoBook

Moderator: Neosoft Support

String replace on certain lines

Postby StarterPack » Sat Nov 19, 2016 2:39 am

Hi guys, is there a way i can replace certain lines with string
Example

.Em_______C
More Love, More Power
.D______________Em
More Of You In My Life

I Want To Replace the lines that started with a . sign ( in this case line 1 and 3) and after every letter it must add a * sign

.Em*___________C*
More Love, More Power
.D*_____________Em*
More Of You In My Life
StarterPack
 
Posts: 115
Joined: Fri Feb 19, 2016 6:55 am

Re: String replace on certain lines

Postby virger » Sat Nov 19, 2016 7:34 am

No entiendo muy bien que es lo que pedis, pero trata esto

Code: Select all
{NeoBook 5 Objects}
NeoBookVer=5,80
ObjectType=10
Name=LsLines
X=32
Y=97
W=219
H=85
Anchor=0
Text=.Em_______C¶More Love, More Power¶.D______________Em¶More Of You In My Life
VarName=[lin]
VarType=0
XPTheme=Yes
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16250871
FillPattern=0
Font=Arial
FontSize=12
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=2
ObjectType=3
Name=BtExe
X=186
Y=186
W=64
H=26
Anchor=0
Text=Exe
Align=2
ImageStyle=0
XPTheme=Yes
ObjAction=ListBoxSize "LsLines" "[sz]"¶..ListBoxSort "LsLines" "True"¶strparse ".Em,_Em,.D,_C" "," "[rep]" "[nRep]"¶loop "1" "[sz]" "[c]"¶    ListBoxGetItem "LsLines" "[c]" "[Lin]"¶    substr "[Lin]" "1" "1" "[ch]"¶..    if "[ch]" "<>" "."¶..        exitloop¶..    endif¶    if "[Ch]" "=" "."¶        setvar "[vLin]" "[Lin]"¶        loop "1" "[nRep]" "[n]"¶            StrReplace "[vLin]" "[Rep[n]]" "[Rep[n]]@" "[vLin]" ""¶        endloop¶        ListBoxChangeItem "LsLines" "[c]" "[vLin]"¶    endif¶endloop¶..ListBoxSort "LsLines" "False"¶..RefreshObject "LsLines"
LineColor=0
LineWidth=1
LineStyle=0
FillColor=12961221
FillPattern=0
Font=Arial
FontSize=12
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=3
COSTA RICA
PURA VIDA
User avatar
virger
 
Posts: 510
Joined: Mon Sep 18, 2006 12:21 pm
Location: Costa Rica, America Central

Re: String replace on certain lines

Postby Gaev » Sat Nov 19, 2016 11:32 am

StarterPack:

1) Where are these lines stored ? ... in a variable or some Text file ?

2) What do you mean by Em ?

3) Your example suggests that you also want to add * at the end of "lines that start with a dot" ... is that true ?
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: String replace on certain lines

Postby StarterPack » Sat Nov 19, 2016 1:28 pm

Hi Gaev

I want to type a song or import a text file in TextEntry box with Multi-line Style enabled. Em is E Minor ( a chord for musicians). I want to add a dot (.) sign on every line that contain chords. With a click of a button it must search every line that starts with a dot (.) sign and if theres a letter in that line, it must add a (*) sign after every letter.

So if i import a text file that looks like this:
Em____________C
More Love, More Power
D_______________Em
More Of You In My Life

without the underscore (___________ ) because this doesn't work here

Now if i put a dot (.) sign on line 1
.Em______________C
It must change that line to
.Em*_____________C*
StarterPack
 
Posts: 115
Joined: Fri Feb 19, 2016 6:55 am

Re: String replace on certain lines

Postby Gaev » Sat Nov 19, 2016 4:57 pm

StarterPack:

Thank you for the detailed explanation.

Is it just the lines starting with Em and D that need to have stars (i.e. *) inserted after these letters AND at the end of these lines ... in other words, if you insert a dot in front of More Love, More Power, what should happen ?
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: String replace on certain lines

Postby StarterPack » Sat Nov 19, 2016 9:41 pm

Hi Gaev

If i import a text file (song lyrics) with chords on top of the words where the chord is supposed to be played in TextEntry box

Now if the chords are on

Line1 - Chords
Lyrics
Line3 - Chords
Lyrics
Line5 - Chords
Lyrics
Line7 - Chords
Lyrics
etc

If i put a dot (.) in the beginning of the lines that contains chords, it must add a star (*) sign after the end of every chord in that row or line and not necessarily end of line.

So it can be chords like ( A, F#m, D#7, Cm7 ) etc.

With StrReplace command i can tell to replace all A with A* but then it changes all the A's even in the lyrics, so i need a way to tell the program that if there's a dot (.) in the beginning of whatever lines, it must only change those lines
StarterPack
 
Posts: 115
Joined: Fri Feb 19, 2016 6:55 am

Re: String replace on certain lines

Postby Gaev » Sat Nov 19, 2016 11:40 pm

StarterPack:

So it can be chords like ( A, F#m, D#7, Cm7 ) etc.

My knowledge of Music is Zero :( ... so, you will have to provide me with a full list of all possible chords i.e. text strings beginning with ..

.A
.F#m
.D#7
.Cm7

... that need to have the stars inserted.

After that, it is just a matter parsing the variable to separate each line into an arrayed variable ... and then doing a Loop/EndLoop to extract and examine each line ... if the line begins with the specific characters (and already does not have the stars), then do the inserts ... and reconstruct the variable by joining each of the lines.
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: String replace on certain lines

Postby virger » Sun Nov 20, 2016 7:29 am

No se si analizaste mi propuesta anterior, bueno esta esta mejorada de acuerdo a tus necesidades, es muy simple.
Disfrutalo

I do not know if you analyzed my previous proposal, well this one is improved according to your needs, it is very simple.
Enjoy it

Code: Select all
{NeoBook 5 Objects}
NeoBookVer=5,80
ObjectType=10
Name=LsLines
X=30
Y=31
W=219
H=303
Anchor=0
Text=.Em¶Hola¶.C¶More Love, More Power¶.D¶Como¶.Em¶More Of You In My Life¶.A¶Alfa¶.F#m¶Beta¶.D#7¶Gama¶.Cm7¶Delta
VarName=[lin]
VarType=0
XPTheme=Yes
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16250871
FillPattern=0
Font=Arial
FontSize=12
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=3
ObjectType=3
Name=BtExe
X=253
Y=32
W=64
H=26
Anchor=0
Text=Exe
Align=2
ImageStyle=0
XPTheme=Yes
ObjAction=ListBoxSize "LsLines" "[sz]"¶loop "1" "[sz]" "[c]"¶    ListBoxGetItem "LsLines" "[c]" "[Lin]"¶    substr "[Lin]" "1" "1" "[ch]"¶    if "[Ch]" "=" "."¶        substr "[Lin]" "2" "9" "[vLin]"¶        ListBoxChangeItem "LsLines" "[c]" "[vLin]*"¶    endif¶endloop
LineColor=0
LineWidth=1
LineStyle=0
FillColor=12961221
FillPattern=0
Font=Arial
FontSize=12
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=2
COSTA RICA
PURA VIDA
User avatar
virger
 
Posts: 510
Joined: Mon Sep 18, 2006 12:21 pm
Location: Costa Rica, America Central

Re: String replace on certain lines

Postby StarterPack » Sun Nov 20, 2016 12:58 pm

Hi Virger

Thank you, but i don't know witch code to insert, because it keeps popup a Error Report that says: I don't understand this command!
This must also work for any lyrics and not necessarily for the ones i supplied.

Gaev, there are hundreds of chords out there. It will be impossible to supply all the chords. I thought there would be easy way to just tell the program that if the line starts with a dot (.) sign, it must change those lines only
StarterPack
 
Posts: 115
Joined: Fri Feb 19, 2016 6:55 am

Re: String replace on certain lines

Postby Gaev » Sun Nov 20, 2016 2:04 pm

StarterPack:
there are hundreds of chords out there. It will be impossible to supply all the chords. I thought there would be easy way to just tell the program that if the line starts with a dot (.) sign, it must change those lines only

That is only part of the logic ... using the existing examples ...

.A
.F#m
.D#7
.Cm7

... notice that the chord strings are of length 1, 2 and 3 ... so how does the computer know where to insert the first star (*) ? ... after 2, 3 or or 4 characters (counting the dot) ?

One solution would be if there was a space (or other unique designated character) between the (variable length) chord and the rest of the line ... then, the first star could be inserted before this designated character.
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: String replace on certain lines

Postby virger » Sun Nov 20, 2016 6:06 pm

Well !
COSTA RICA
PURA VIDA
User avatar
virger
 
Posts: 510
Joined: Mon Sep 18, 2006 12:21 pm
Location: Costa Rica, America Central

Re: String replace on certain lines

Postby StarterPack » Mon Nov 21, 2016 3:19 am

where must i put that code virger
StarterPack
 
Posts: 115
Joined: Fri Feb 19, 2016 6:55 am


Return to General NeoBook Discussions

Who is online

Users browsing this forum: No registered users and 2 guests