Author Posts

January 1, 2012 at 12:00 am

by TomKemp at 2012-11-22 09:01:35

I have a problem with splitting a string into parts.

I have a script which produces something like:


InheritanceEnabled : False
AccessControlType : Allow
Account : NT AUTHORITY\SYSTEM (S-1-5-18)
AccessRights : FullControl
InheritanceFlags : ContainerInherit, ObjectInherit
IsInherited : False

What I am trying to do is to make this display on a Windows Form so the : all appear in a vertical line.

I have tried to add some formatting to the original output but this is not working, so I tried to replace the RichTextBox with a ListView. The problem is that the output is all in one long string, including newline characters.

I am trying to separate this into something like this:


Column1 Column2
-----------------------------------------------
InheritanceEnabled False
AccessControlType Allow
Account NT AUTHORITY\SYSTEM (S-1-5-18)
AccessRights FullControl
InheritanceFlags ContainerInherit, ObjectInherit
IsInherited False

Hope this explains the problem.

Is there a better way to format the original string on a RichTextBox instead please?

Ironically, the above does not show exactly my problem – which is that the original does NOT align the : characters. That is what I am trying to do.

by DonJ at 2012-11-23 12:16:44

You should be using a ListView or GridView for this, and putting your information into discrete cells/columns, rather than attempting to format them out manually. Because the metrics of a RichTextBox will differ based on the user's selected font family, font size, etc., you'll never get things to reliably line up that way. Worst case, use a normal TextBox control and set its font to Courier or something.