Solved

Replacing  character in the script

Posted on 2008-10-14
9
844 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
  • 4
  • 3
  • 2
9 Comments
 
LVL 13

Expert Comment

by:TechTiger007
Comment Utility

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
Comment Utility
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
Comment Utility
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
 
LVL 13

Expert Comment

by:TechTiger007
Comment Utility
Are you using the same variable "Decl " to write into rtf file?  
Please post the code snippet.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:learningnet
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now