Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Remove "Non Text / Numeric" values from String

Posted on 2010-09-02
7
Medium Priority
?
791 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 2000 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
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 8

Expert Comment

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

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 75

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 75

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

971 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