Tuesday, 28 July 2009

Trimming text notes

It's been 20 days since my last post, in which time the Pitt family has grown by one and I've done very little programming, choosing sleep in my down-time rather than looking at a screen. But here's an issue I made a draft entry of a while back but never posted it for some reason.

I had some Revit files that were showing unexpected characters at the end of inserted text notes. I say unexpected, as I wasn't expecting them, so neither was our software. Closer inspection revealed these to be linefeeds or carriage returns, unprintable in your everyday text editors but nonetheless there when handling the data and making database comparisons. They got there because of the tendency to hit 'return' when completing a text note; something unpreventable, so I have to clean them up.

I looked into the .net String.Trim method, but this didn't seem to work. Then I had a look at String.Replace, to replace the offending character with nothing. The problem then was identifying what the character actually was. I tried \n, VbCrlf, etc etc to no avail.

Then after a coffee I tried Trim(String), which I had imagined did the same thing as String.Trim. This time it worked.

So what's the difference between String.Trim and Trim(String)?

Public Function Trim(ByVal str As String) As String
Member of Microsoft.VisualBasic.Strings
Returns a string containing a copy of a specified string with no leading spaces (LTrim), no trailing spaces (RTrim), or no leading or trailing spaces (Trim).

Public Function Trim() As String
Member of System.String
Removes all leading and trailing white-space characters from the current System.String object.

Subtle, and not entirely clear, but it works for me :)

1 comment:

  1. Did you ever figure out a way to just have Revit recognize those characters? I am having trouble currently because I'm creating text notes with tab characters in them, but they show up as boxes until the user clicks inside the text note to edit them, then they turn into "real" tabs.


Comments are moderated, so you'll have to wait a little bit before they appear!