SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I have records where I need to replace one letter with another.

    I need your advice on this.

    Can I modify this highlighting code to do that?

    What I need to do is to update my table of database where a column has to replace one letter with another.

    WHat I have is the "insert into" statement where I duplicated the table (not shown below).

    Code:
    <SCRIPT LANGUAGE="VBSCRIPT" RUNAT="SERVER">
    Function Highlight(strText, strFind, strBefore, strAfter)
      Dim nPos
      Dim nLen
      Dim nLenAll
      
      nLen = Len(strFind)
      nLenAll = nLen + Len(strBefore) + Len(strAfter) + 1
    
      Highlight = strText
    
      If nLen > 0 And Len(Highlight) > 0 Then
        nPos = InStr(1, Highlight, strFind, 1)
        Do While nPos > 0
          Highlight = Left(Highlight, nPos - 1) & _
            strBefore & Mid(Highlight, nPos, nLen) & strAfter &_
             Mid(Highlight, nPos + nLen)
    
          nPos = InStr(nPos + nLenAll, Highlight, strFind, 1)
        Loop
      End If
    End Function
    </SCRIPT>
    <%
    'OPTION EXPLICIT
    Dim strText, strFind
    strFind=Keyword
    strText=RS("new_text_data")
    strText= Highlight(strText, strFind,"<font color='red'><b>", "</b></font>")
    Response.Write strText
    %>
    Compare bible texts (and other tools):
    TheWheelofGod

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure what you mean, please explain better.

  3. #3
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    replace string + update table

    I want to replace the string. I have an anglicized hebrew table. But I need to change a character, like "A" with ")" for the entire table's column.

    Do I use the replace function like the one above used for highlighting? (What modifications need to be made then?) and the "SELECT INTO" or "UPDATE" to correct the table column?

    Or what?
    Compare bible texts (and other tools):
    TheWheelofGod

  4. #4
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is a REPLACE function for SQLServer, not sure what other database servers support it, that you might be able to use, something like

    UPDATE Mytable SET MyRow=REPLACE(MyRow,'A',')')

    You might need to ask the SQL people in the databases section as I'm unsure if this will work.

    Otherwise, there's always:
    <%
    oRS = myDB.Execute("SELECT * FROM MyTable")
    Do While Not oRS.EOF
    myDB.Execute "UPDATE MyTable SET MyRow='" & Replace(oRS.Fields("MyRow"),"A",")") & "' WHERE MyId=" & oRS.Fields("MyId")
    oRS.MoveNext
    Loop
    %>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •