Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Remove "Non Text / Numeric" values from String

Posted on 2010-09-02
7
Medium Priority
?
787 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
DFW AZURE MEETUP TONIGHT FRI 6PM

We will be discussing what Azure Stack is, how does it fit into the suit of offerings that Azure has currently, and where can it fit into your organizations technology stack. We will also be discussing limitations of the platform while covering various applicable scenarios.

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

705 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