Solved

Remove "Non Text / Numeric" values from String

Posted on 2010-09-02
7
779 Views
Last Modified: 2013-11-27
I've developed a VB.NET application that does the following

1) Opens up a Text File
2) Searches through the text file line by line to find specific strings of information in the row.
3) After searching through the row, it inserts information into an SQL Server database.
4) From SQL Server, I export the data into a fixed width format text file.

Here is my problem.  When I export the file to the fixed width format from SQL Server, the fixed width layout is not maintained.  For example, the first field in my export has a width of 50.  When I export to the fixed width, there are records where this field will have a width of 51 which throws the rest of the layout off by 1 character.

I believe the reason for this is that there is some type of "non-text" character in the string such that when I export to text file it adds a space to the width.

Is there a way that I can remove these types of characters from the string value within VB.NET?

I think that Regular Expressions would be the way to go, but I'm not sure how to do this.
0
Comment
Question by:tfewster500
7 Comments
 
LVL 8

Expert Comment

by:Gururaj Badam
ID: 33586257
I think you will have to check the max length for every column and set the fixed width to length + 1 to get a proper format
0
 
LVL 11

Expert Comment

by:madgino
ID: 33586278
This is too general, we need more info. Is there an extra space in the 51 string or a different one each time, are the values right in the sql db or not, are the values right before inserting to sql or not, how do you do the export?
0
 
LVL 5

Accepted Solution

by:
roxviper earned 500 total points
ID: 33586301
Hi,

Maybe the most elegant way to do it is with Regex,as you said.

For that check those links:

http://visualbasic.about.com/od/usingvbnet/a/RegExNET_2.htm

and this. A gallery with some usual regex

http://wiki.tcl.tk/989
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 8

Expert Comment

by:Gururaj Badam
ID: 33586437
How are you exporting the data to the text file?
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 33591804
>>  Is there a way that I can remove these types of characters from the string value within VB.NET?

Sure. I've started the pattern for you, but if you need to allow any other characters, add them inside the square brackets--please be sure to leave the dash at the end (unless you remove it).
Dim result As String = System.Text.RegularExpressions.Regex.Replace(your_text, "[^a-zA-Z0-9 $%#@!*&()[\]""':;-]")

Open in new window

0
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 33591817
Forgot the replacement!
Dim result As String = System.Text.RegularExpressions.Regex.Replace(your_text, "[^a-zA-Z0-9 $%#@!*&()[\]""':;-]", String.Empty)

Open in new window

0
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 33591830
P.S.

Do not remove the caret ( ^ ) immediately following the opening square bracket as that would change the meaning of the pattern.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now