Convert and Transpose Text to an Additional Location

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, MudGuard

Post Reply
jmca2000
Posts: 15
Joined: Thu Feb 24, 2011 5:09 pm

Convert and Transpose Text to an Additional Location

Post by jmca2000 »

Hi, I'm New to TextPad and Regular Expressions.

I have over 2500 of the following test conditions in my code in C# :

if (//upDown_129
whiteLineDown
&& orangeLineUp
&& yellowLineDown
&& cyanLineDown
&& blackLineDown
&& dodBlueLineDown
&& blueLineDown
&& greenLineDown
&& redLineDown
)
{
upDown_129 = true ;
DrawText("upDown_129" + DateTime.Now.Millisecond.ToString() + CurrentBar + DateTime.Now.Millisecond.ToString()
+ CurrentBar + CurrentBar + DateTime.Now.Millisecond.ToString(), "^129", 0, Low[0]-(TickSize*12), Color.Black);
Print("//upDown_129");
}

I would like the code to look like the following when changed: :?:

if (//upDown_129
whiteLineDown
&& orangeLineUp
&& yellowLineDown
&& cyanLineDown
&& blackLineDown
&& dodBlueLineDown
&& blueLineDown
&& greenLineDown
&& redLineDown
)
{
upDown_129 = true ;
DrawText("upDown_129" + DateTime.Now.Millisecond.ToString() + CurrentBar + DateTime.Now.Millisecond.ToString()
+ CurrentBar + CurrentBar + DateTime.Now.Millisecond.ToString(), "^129", 0, Low[0]-(TickSize*12), Color.Black);
Print("//upDown_129");
Print("&& whiteLineDown");
Print("&& orangeLineUp");
Print("&& yellowLineDown");
Print("&& cyanLineDown");
Print("&& blackLineDown");
Print("&& dodBlueLineDown");
Print("&& blueLineDown");
Print("&& greenLineDown");
Print("&& redLineDown");
}


It's basically the same thing, just want to convert the "conditions" in the "if" part of the statement to a Print statement in the "then" part of the "if" statement.

I'm assuming that I would probably have to Convert and Transpose these test conditions one at a time (which is OK).

Thank You Very Much For Your Support in Advance. :)
Joe Cagg
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

The best way to do this is with a script. But TextPad doesn't support scripts. Perhaps you can do it with a macro. I'm not an expert on TextPad's macros, as they are too weak for my purposes and can't be edited. I always use scripts for this sort of thing.
jmca2000
Posts: 15
Joined: Thu Feb 24, 2011 5:09 pm

Post by jmca2000 »

Ben, Could you then just Please help me with the following:

Convert this:
if (//upDown_1
whiteLineDown
&& orangeLineDown
&& yellowLineDown
&& cyanLineDown
&& blackLineDown
&& dodBlueLineDown
&& blueLineDown
&& greenLineDown
&& redLineDown
)
{
upDown_1 = true ;
DrawText("upDown_1" + DateTime.Now.Millisecond.ToString() + CurrentBar + DateTime.Now.Millisecond.ToString()
+ CurrentBar + CurrentBar + DateTime.Now.Millisecond.ToString(), "^1", 0, Low[0]-(TickSize*12), Color.Black);
Print("//upDown_1");

}

To:
if (//upDown_1
Print("whiteLineDown");
Print("&& orangeLineUp");
Print("&& yellowLineDown");
Print("&& cyanLineDown");
Print("&& blackLineDown");
Print("&& dodBlueLineDown");
Print("&& blueLineDown");
Print("&& greenLineDown");
Print("&& redLineDown");
)
{
upDown_1 = true ;
DrawText("upDown_1" + DateTime.Now.Millisecond.ToString() + CurrentBar + DateTime.Now.Millisecond.ToString()
+ CurrentBar + CurrentBar + DateTime.Now.Millisecond.ToString(), "^1", 0, Low[0]-(TickSize*12), Color.Black);
Print("//upDown_1");

}


When I use your code I get the following:
Print("&& if (//upDown_1");
Print("&& whiteLineDown");
Print("&& orangeLineDown");
Print("&& yellowLineDown");
Print("&& cyanLineDown");
Print("&& blackLineDown");
Print("&& dodBlueLineDown");
Print("&& blueLineDown");
Print("&& greenLineDown");
Print("&& redLineDown");
Print("&& )");
Print("&& {");
Print("&& upDown_1 = true ;");
Print("&& DrawText("upDown_1" + DateTime.Now.Millisecond.ToString() + CurrentBar + DateTime.Now.Millisecond.ToString()");
Print("&& + CurrentBar + CurrentBar + DateTime.Now.Millisecond.ToString(), "^1", 0, Low[0]-(TickSize*12), Color.Black);");
Print("&& Print("//upDown_1");");

Print("&& }");
Thanks in Advance.
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Try this:
Find what: ^(&& )?[a-z]+$
Replace with: Print("\0");

[ ] Match case [i.e., not selected]
[X] Regular expression

Replace All
jmca2000
Posts: 15
Joined: Thu Feb 24, 2011 5:09 pm

Post by jmca2000 »

Hi Ben,

Thanks for your Help. I used the code you gave me but I got the Following response: "Cannot find regular expression:" ^(&& )?[a-z]+$.

I used just Regular expression Not POSIX. ???

The only other thing I know of is that there may be Leading Tabs or Spaces and I don't know how to do an all in one or two clean up to get rid of them if this is the problem.

Thanks Joe
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Do you mean you reverted to non-"Posix" regular expression syntax? Why?

To show your examples with their original layout, including leading white space, enclose them in

Code: Select all

[/color][/b] ... [b][color=blue]
[/color][/b] tags (without the space I've added to stop the tags being interpreted here).

Try this:
Find what: ^([ \t]*)((&& )?[a-z]+)$
Replace with: \1Print("\2");

[ ] Match case [i.e., not selected]
[X] Regular expression

Replace All
jmca2000
Posts: 15
Joined: Thu Feb 24, 2011 5:09 pm

Post by jmca2000 »

Ben,

Your original code showed Only:

Find what: ^(&& )?[a-z]+$
Replace with: Print("\0");
[ ] Match case [i.e., not selected]
[X] Regular expression
Replace All

That's why I removed the POSIX.

IT WORKED :)

I don't understand what you mean by:

"To show your examples with their original layout, including leading white space, enclose them in

Code: Select all

 ... 
tags :?: (without the space I've added to stop the tags being interpreted here)." :?:

One other thing with this is if I changed the information from up and down to:

whiteLineAbovePrice_N
&& orangeLineAbovePrice_N
&& yellowLineAbovePrice_N
&& cyanLineAbovePrice_N
&& blackLineAbovePrice_N
&& dodBlueLineAbovePrice_N
&& blueLineAbovePrice_N
&& greenLineAbovePrice_N
&& redLineAbovePrice_Y

It did Not work? I don't think much has changed?

Also I will have to change :

whiteLineAtPrice_N
&& orangeLineAtPrice_N
&& yellowLineAtPrice_N
&& cyanLineAtPrice_N
&& blackLineAtPrice_N
&& dodBlueLineAtPrice_N
&& blueLineAtPrice_N
&& greenLineAtPrice_Y
&& redLineAtPrice_N

And one last one:

whiteLineBelowPrice_N
&& orangeLineBelowPrice_N
&& yellowLineBelowPrice_N
&& cyanLineBelowPrice_N
&& blackLineBelowPrice_N
&& dodBlueLineBelowPrice_N
&& blueLineBelowPrice_Y
&& greenLineBelowPrice_Y
&& redLineBelowPrice_Y

Thanks Again, So Much for your Help! Joe
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Change the regex to
^([ \t]*)((&& )?[a-z_]+)$

I think it may be time for you to learn something about regular expressions for yourself.

You may find it helpful to read TextPad's help on regular expressions, although it's rather brief. Look under
Reference Information | Regular Expressions,
Reference Information | Replacement Expressions and
How to... | Find and Replace Text | Use Regular Expressions.

There are many regular expression tutorials on the web, and you will find recommendations for some of them if you search this forum.

A standard reference for regular expressions is

Friedl, Jeffrey E F
Mastering Regular Expressions, 3rd ed
O'Reilly, 2006
ISBN: 0-596-52812-4
http://regex.info/

But be aware that the regular expression recogniser used by TextPad is very weak compared with modern tools. So you may get frustrated if you discover a handy trick that works elsewhere but doesn't work in TextPad.
jmca2000
Posts: 15
Joined: Thu Feb 24, 2011 5:09 pm

Post by jmca2000 »

Ben, Sincerely THANKs for all your help with this.

I'm on a time restraint with my C# program.

I did do some research on your forum site and learned how to delete Blank lines with and without // in them and also how to add a blank line and remove spaces and tabs from a blank line (not truely understanding what the syntax is doing) before posting these questions.

When I get some extra time I Do Intend to learn more about Regular Expressions since it is such a powerful code editing tool.

But in the interim could you Please just elaborate on this last thing for know regarding:

"To show your examples with their original layout, including leading white space, enclose them in

Code: Select all

 ... 
tags (without the space I've added to stop the tags being interpreted here)."

When I used the code you gave me, it keep the original format in tact, so I'm not sure what you mean when you say "enclose them in

Code: Select all

 ... 
tags".

THANKS ONCE AGAIN FOR EVERYTHING :!:
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

This isn't my site. I'm just a user.

I was suggesting how you might better display code examples in posts on the site.

Without the

Code: Select all

[/color][/b] ... [b][color=blue]
[/color][/b] tags your code example might look like this:

if (//upDown_1
whiteLineDown
&& orangeLineDown
)
{
upDown_1 = true ;
Print("//upDown_1");
}

With the tags it might look like this:

Code: Select all

if (//upDown_1
      whiteLineDown
   && orangeLineDown
   )
{
  upDown_1 = true ;
  Print("//upDown_1");
}
jmca2000
Posts: 15
Joined: Thu Feb 24, 2011 5:09 pm

Post by jmca2000 »

Thanks Ben For ALL your Time and Help, May it come back to you 10 Fold.
Post Reply