Solved

Replacing  character in the script

Posted on 2008-10-14
9
853 Views
Last Modified: 2008-10-15
Hello Experts


I have a column holding this data  +5° 41' 50.2"

For some reason when I print it to the rtf file I am getting something like this

+5° 41' 50.2"

Although I am replacing this character with null in my ASP.Net script but it is still appearing it.

Decl = dt.Rows(i).Item("StarDecl")
 Decl = Decl.Replace(Chr(194), "")

Can somebody please advise me here?

thanks for your help

regards
kay
0
Comment
Question by:learningnet
[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
  • 4
  • 3
  • 2
9 Comments
 
LVL 13

Expert Comment

by:TechTiger007
ID: 22712458

I tried the code below and it worked fine

 Dim Decl As String = "+5° 41' 50.2"
 Decl = Decl.Replace(Chr(194), "")

Is it throwing any exception?
Debug the code and check what is the value in Decl before and after you call Replace method
0
 

Author Comment

by:learningnet
ID: 22712851
hello TechTiger007:
no it is not throwing any exception nor it is showing up anything while i debug ...

i am getting 500 of such  "+5° 41' 50.2" from the database and printing them on the rtf file.

only few records  it is getting printed like this "+5° 41' 50.2" and for the rest its fine...

i do not understand why it is behaving like this .....

please advise
0
 

Author Comment

by:learningnet
ID: 22713341
i am trying to generate RTF file reading these codes from the DB,

please see attached for  DEC: +1° 13' 35.2"

although there is only +1° 13' 35.2" in the DB however it is printing this special character when I view it in the word document after generating the rtf file

please advise
{\rtf1
\fs16
\ql
                    Star Code: STAR222YUUKXGF   - Expires: 14/10/2010
\par
\par
                    AGASC_ID: 2098384
\par
\par
                    RA: 0h 38m 34.1s
\par
\par
                    DEC: +6° 33' 39.7"
\par
\par
                    MAG: 10.4
\page
\ql
                    Star Code: STAR2237T5U6PB   - Expires: 14/10/2010
\par
\par
                    AGASC_ID: 393576
\par
\par
                    RA: 0h 27m 40.8s
\par
\par
                    DEC: +1° 13' 35.2"
\par
\par
                    MAG: 12.7
}

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Expert Comment

by:TechTiger007
ID: 22713399
Are you using the same variable "Decl " to write into rtf file?  
Please post the code snippet.
0
 

Author Comment

by:learningnet
ID: 22715509
hello techtiger007

please have it attached, i was going through one of the post on EE with quite similar issue

is it a space which is adding that character?

someone advise to use windows encoding ...


            'MyFile = StreamWriter(path, System.Text.Encoding.GetEncoding("windows-1252"))

please can you advise?

thanks for your time and help
 Private Sub GenerateStarCodes(ByVal NumCodes As Integer)
        Dim RegionID As Integer = lstStarRegion.SelectedValue
        Dim dt As DataTable
 
        dt = GiftCode.GetStarCodesToCreate(NumCodes, RegionID)
 
        Dim FileName, GiftCodeID As String
        Dim dbconn, writeConn As SqlConnection
        Dim writeComm As SqlCommand
        Dim trans As SqlTransaction = Nothing
        'Dim SQL As String
        'Dim dbcomm As SqlCommand
        'Dim dbread As SqlDataReader
        Dim RTF As System.IO.StreamWriter
        'Dim CodeLength As Integer
        Dim Decl As String
        'Dim Decl As String
 
        'Open the connection to the database for the Stored Procedure
        writeConn = New SqlConnection(ConfigurationManager.ConnectionStrings("Giftstring").ConnectionString)
        writeConn.Open()
 
        'Start the transaction
        writeComm = New SqlCommand()
        writeComm.Connection = writeConn
        writeComm.CommandType = CommandType.StoredProcedure
        writeComm.CommandText = "procCreateStarCode"
        writeComm.Parameters.Add("@GiftCodeID", SqlDbType.Char, 16)
        writeComm.Parameters.Add("@UserID", SqlDbType.Char, 10)
 
        GiftCodeID = ""
 
        Try
            trans = writeConn.BeginTransaction
            writeComm.Transaction = trans
 
            Dim TypeID As String = Trim(lstProduct.SelectedValue)
 
 
            'Create the RTF file
            FileName = RTFLocation & TypeID & "-" & WebFunctions.FormatMySQLDate(Date.Now()) & "-" & Right("0" & Date.Now.Hour, 2) & "-" & Right("0" & Date.Now.Minute, 2) & "-" & Right("0" & Date.Now.Second, 2) & ".RTF"
            RTF = New System.IO.StreamWriter(FileName)
            'System.Text.Encoding.GetEncoding("windows-1252")
            RTF.WriteLine("{\rtf1") ' open rtf
            RTF.WriteLine("\fs16")
 
            Dim DateString As String
            DateString = WebFunctions.FormatMySQLDate(Date.Now.AddMonths(24))
 
            dbconn = New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("GiftString").ConnectionString)
            dbconn.Open()
 
            If dt.Rows.Count > 0 Then
                For i As Integer = 0 To NumCodes - 1
                    If i > 0 Then
                        RTF.WriteLine("\page")
                    End If
 
                    GiftCodeID = dt.Rows(i).Item("GiftCodeID")
 
                    RTF.WriteLine("\ql")
                    RTF.WriteLine("                    Star Code: " & GiftCodeID & " - Expires: " & WebFunctions.FormatDateWithZeros(Date.Now().AddYears(2)))
                    RTF.WriteLine("\par")
                    RTF.WriteLine("\par")
                    RTF.WriteLine("                    AGASC_ID: " & dt.Rows(i).Item("StarAGASCID"))
                    RTF.WriteLine("\par")
                    RTF.WriteLine("\par")
                    RTF.WriteLine("                    RA: " & dt.Rows(i).Item("StarRA"))
                    RTF.WriteLine("\par")
                    RTF.WriteLine("\par")
 
                    Decl = dt.Rows(i).Item("StarDecl")
                    Decl = Decl.Replace(Chr(194), "")
                    'Dim c As String
                    'If c = "°" Then
 
                    'End If
                    'For x As Integer = 1 To Decl.Length
                    'c = Decl.Chars(x)
                    'Next
                    RTF.WriteLine("                    DEC: " & Decl)
                    RTF.WriteLine("\par")
                    RTF.WriteLine("\par")
                    RTF.WriteLine("                    MAG: " & dt.Rows(i).Item("StarMagnitude"))
 
                    'Add the code to the database
                    writeComm.Parameters("@GiftCodeID").Value = GiftCodeID
                    writeComm.Parameters("@UserID").Value = Session("BackendUserID")
                    writeComm.ExecuteNonQuery()
                Next
            End If
 
            RTF.WriteLine("}")
            RTF.Close()
 
            'Email the document
            Dim Files As New Collection
            Files.Add(FileName)
            WebFunctions.SendEmail("admin@gublic.com", EmailTo, lstProduct.SelectedItem.Text & " Codes", "", Files)
 
            trans.Commit()
 
            lblFeedback.Text = NumCodes & " codes for " & TypeID & " created and emailed to " & EmailTo
            lblFeedback.Visible = True
        Catch
            If Not trans Is Nothing Then
                trans.Rollback()
            End If
            If Not RTF Is Nothing Then
                RTF.Close()
            End If
            lblFeedback.Text = "Codes not created. See the Application Administrator"
            lblFeedback.Visible = True
        End Try
    End Sub

Open in new window

0
 
LVL 13

Assisted Solution

by:TechTiger007
TechTiger007 earned 245 total points
ID: 22719955
Are you sure that they are all same characters or the variants like
À
Á
Â
Ã
Ä
Å
Here is ANSI chart for characters
http://www.alanwood.net/demos/ansi.html

This could be also problem with encoding. Please try it out with ANSi encoding and windows encoding that you mentioned and let me know
0
 

Accepted Solution

by:
darek1211 earned 255 total points
ID: 22721215
I was the one that was referred to earlier above.  I can only offer my code snipped that worked in the end.

replace your :

        RTF= New System.IO.StreamWriter(FileName)

with:

       RTF = New System.IO.StreamWriter(Filename, True, System.Text.Encoding.GetEncoding("windows-1252"))

0
 

Author Comment

by:learningnet
ID: 22721765
thanks darek1211

your suggestion worked like a charm ... !!

i was like all on it since yesterday, tried all what i can ....

hats off to the techies ( TechTiger007 & darek1211)

cheers
kay
0
 

Expert Comment

by:darek1211
ID: 22722251
glad it worked :) i spent a lot of time on it too, until i asked the question here and got it resolved in a day.  glad we have this experts-exchange resource to help us out :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

734 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