Go Back   CORTEX Forums > Local Happenings > CORTEX Blogs > BI Monkey
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read

Convert Text Stream to String

This is a discussion on Convert Text Stream to String within the BI Monkey forums, part of the CORTEX Blogs category; One of the ongoing challenges with SSIS is its difficulty in handling complex or damaged text files. One approach to dealing with such files is to bring them all in ...


Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 6th September 2010, 12:22 PM   #1
Guru
 
Join Date: Jun 2009
Posts: 135
James Beresford is on a distinguished road
Thumbs up Convert Text Stream to String

One of the ongoing challenges with SSIS is its difficulty in handling complex or damaged text files. One approach to dealing with such files is to bring them all in as one*wide text column and then split them using code. Sometimes, the file is too wide for that approach, so below is an extension of that method where you import the column as a text stream (DT_TEXT, or Unicode DT_NTEXT) and then split the text stream in a script transformation:
******* ‘ Declare variables
******* Dim TextStream As Byte()*********** ‘ To hold Text Stream
******* Dim TextStreamAsString As String*** ‘ To Hold Text Stream converted to String
******* Dim StringArray() As String******** ‘ To contain split Text Stream

******* ‘ Load Text Stream into variable
******* TextStream = Row.TextStreamColumn.GetBlobData(0, CInt(Row.Column0.Length))


******* ‘ Convert Text Stream to string
******* TextStreamAsString = System.Text.Encoding.ASCII.GetString(TextStream)


******* ‘ Split string into array and output
******* StringArray = TextStreamAsString.Split(“#”) *******

******* Row.Column1 = StringArray(1).ToString
******* Row.Column2 = StringArray(2).ToString
******* Row.Column3 = StringArray(3).ToString**

An important thing to note*is that in the step where the Text Stream is converted to a string, the Encoding will depend on the type of text stream you are bringing in – Unicode files will need*”Unicode” instead of “ASCII”. Also I have used a hash (”#”) as the*column delimiter but that value will vary depending on what type of file you are bringing in.



Get More from the original blog...
James Beresford is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiTweet this Post!
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
A Kite with a Broken String Latest News Headlines Other International Vendors 0 26th May 2010 04:38 AM
How Badly Does Europe Want to Convert to Wind Power? admin Prediction Markets News Feeds 0 23rd April 2010 06:09 AM
IT Stream Lead W (S37) admin 2010 Job Archive 0 11th March 2010 11:37 PM
ATM fees convert Customers cash Latest News Headlines 2009 Q3 News Headlines 0 14th August 2009 09:58 AM
Replacing multiple characters in a Text String in SSIS James Beresford BI Monkey 0 30th June 2009 05:09 PM


All times are GMT +11. The time now is 10:33 PM.

© The Business Intelligence Group

Search Engine Optimization by vBSEO