Finding a simple way to align text

I have a common problem with which I am looking for a solution. I have lines of similar text, I would like to somehow insert the text to align them vertically such that:

x="foo" data="123" y=x x="b 4" data="12 " y=x x="baaar4" data="123aaa5" y=x x="baaaa,4" data="123dddd5" y=x 

becomes this

 x="foo" data="123" y=x x="b 4" data="123 " y=x x="baaar4" data="123aaa5" y=x x="baaaa,4" data="123dddd5" y=x 

This is a text issue. Login comes from a notebook. The output will be in a notebook. This is not a formatting issue.

+45
notepad ++
Jan 10 '12 at 18:03
source share
4 answers

Notepad ++ has a plugin that does this for you. It is called code alignment . It allows you to align text vertically based on your chosen characters. You can install it through the Plugin Manager for notepad.

The following is a simple use case. You start with the following code, then you align to "equals", which is the built-in shortcut / command for the plugin.

Initial Code Sample, without alignment

After that, you will get the following:

Code after equals alignment

You can also take another step and use the "align by ..." command, which allows you to specify any arbitrary alignment string. In the example below, I selected the “#” symbol to align my comments next to each other. It would just as easily be a longer string rather than one length.

Final result:

Final result after arbitrary code alignment string

+54
Feb 08 2018-12-12T00:
source share

If you want to align with certain characters, use the Notepad ++ TextFX extension.

Take a look: TextFX> TextFX Edit> Align multiple lines with (,)

There is also: align multiple lines (=) and align multiple lines (clipboard character)

Here is a link to useful programming tips.

http://techbrij.com/518/10-notepad-tips-tricks-fast-development

+24
Dec 12 '12 at 8:01
source share

You did not specify a programming language, so here are a few C # that perform the requested operation:

 int[] maxLengths = new int[100]; string[][] splitLines = new string[input.Length][]; for (int i = 0; i < input.Length; i++) { splitLines[i] = input[i].Split(' '); for (int j = 0; j < splitLines[i].Length; j++) { maxLengths[j] = Math.Max(maxLengths[j], splitLines[i][j].Length); } } for (int i = 0; i < splitLines.Length; i++) { for (int j = 0; j < splitLines[i].Length; j++) { Console.Write(string.Format("0,-" + (maxLengths[j] + 1) + ":G}", splitLines[i][j])); } Console.WriteLine(); } 

Note that 100 must be greater than or equal to the number of segments per row. You can make this number not correct with little work if you want.

Basically, this algorithm breaks each line based on spaces, then for each part it calculates the maximum in the total array. Finally, it goes through all these segmented parts and prints them left-aligned using spaces to the largest size (plus 1 to get a space between the elements).

0
Jan 10 2018-12-12T00:
source share

I created a Python Script that can be used with the Python Script Plugin in Notepad ++: nppPyAlignColumn

0
Oct 22 '14 at 14:21
source share



All Articles