Replacing  character in the script

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
learningnetAsked:
Who is Participating?
 
darek1211Commented:
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
 
TechTiger007Commented:

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
 
learningnetAuthor Commented:
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
learningnetAuthor Commented:
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
 
TechTiger007Commented:
Are you using the same variable "Decl " to write into rtf file?  
Please post the code snippet.
0
 
learningnetAuthor Commented:
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
 
TechTiger007Commented:
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
 
learningnetAuthor Commented:
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
 
darek1211Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.