Replacing Text in a Table with Formatted text

Hello All,

So I am working on a bit of script to replace cells in my tables with new information. It looks for the thing I want to replace and replaces it with new text. I have managed to do this part.

The problem I am having is that when I am writing the code, I would like to have the option to add a newline into the cell. I want to do this when I put in the new string, but when I use \n or \r it just exports "\r".

Is there a way to do this other than having some code which looks for that character in the string I say I want to replace, separates the code, and then adds the newline and the 2 different string to the write to cell?

' ------------------------------------------------------------------------------------------------------------
' NX 8.5.2.3
' Replace Cell Text
' Created 13 Jan 2017
' ------------------------------------------------------------------------------------------------------------

Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpenUI
Imports NXOpen.UF

Module Label_Information_Extraction

'--------------------------------------
' Sets up the NX session
'--------------------------------------

Dim theSession As Session = Session.GetSession()
Dim theUISession As UI = UI.GetUI
Dim theUfSession As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work

Sub Main()

'--------------------------------------
' Opens the Listing Window
'--------------------------------------

Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Dim OldText As String = ""
Dim NewText As String = ""
Dim NewText2 As String = ""
Dim NumberOfReplacements As Integer = 0

OldText = NXInputBox.GetInputString("Input the String you would like to replace:", "Table Text Replacement")
NewText = NXInputBox.GetInputString("Input the String you would like to the old text with:", "Table Text Replacement")
NewText2 = NXInputBox.GetInputString("Input the String you would like to the old text with:", "Table Text Replacement")

lw.WriteLine("You would like to replace: " & OldText & " with: " & NewText & "." )

If NewText != "" Then
FindTabularNotes(lw, OldText, NewText, NewText2, NumberOfReplacements)
Else
lw.WriteLine("You did not insert Text, if you want to replace please run again")
End If

lw.WriteLine("We found and replaced: " & NumberOfReplacements.ToString() & " occurances of " & OldText & " with: " & NewText & ".")

End Sub

Sub FindTabularNotes(lw As ListingWindow, OldText As String, NewText As String, NewText2 As String, ByRef numreplaced As Integer)

Dim tmpTabNote As NXOpen.Tag = NXOpen.Tag.Null
Dim NxType As Integer
Dim NxSubtype As Integer
Dim tmpTabNoteObj as displayableObject
Dim numTables As Integer = 0

Do
theUfSession.Obj.CycleObjsInPart(workPart.Tag, UFConstants.UF_tabular_note_type, tmpTabNote)

If tmpTabNote <> NXOpen.Tag.Null Then

theUfSession.Obj.AskTypeAndSubtype(tmpTabNote, NxType, NxSubtype)

If NxSubtype = UFConstants.UF_tabular_note_subtype Then

'Now we need to search for text
FindReplaceText(tmpTabNote, lw, OldText, NewText, NewText2 , numreplaced)
numTables += 1

End If

End If

Loop Until tmpTabNote = NXOpen.Tag.Null

End Sub

Sub FindReplaceText(tmpTabNote As Tag, lw As ListingWindow, OldText As String, NewText As String, NewText2 As String, ByRef numreplaced As Integer)

Dim rowTag As Tag = Nothing
Dim colTag As Tag = Nothing
Dim numRows As Integer = 0
Dim numCols As Integer = 0
Dim cellText As String = ""
Dim NewCellText As String = ""
Dim cellTag As Tag = Nothing

theUfSession.Tabnot.AskNmColumns(tmpTabNote , numCols)
theUfSession.Tabnot.AskNmRows(tmpTabNote , numRows)

For y As Integer = 0 To numRows-1

For x As Integer = 0 To numCols-1

theUfSession.Tabnot.AskNthRow(tmpTabNote , y, rowTag)
theUfSession.Tabnot.AskNthColumn(tmpTabNote , x, colTag)
theUfSession.Tabnot.AskCellAtRowCol(rowTag, colTag, cellTag)
theUfSession.Tabnot.AskCellText(cellTag, cellText)

If celltext.Contains(OldText) Then
numreplaced += 1
NewCellText = celltext.Replace(OldText, NewText)
If NewText2 != "" Then
theUfSession.Tabnot.SetCellText(cellTag, NewCellText & vbLf & NewText2)
Else
theUfSession.Tabnot.SetCellText(cellTag, NewCellText)
End If
End If

Next

Next

End Sub

End Module

Try adding a "Chr(10)" instead of "\r". Reference your previous, related thread:
http://nxjournaling.com/content/finding-newline-tabular-note-and-replaci...

Ah thank you. I'll try it that way and let you know how I get on. Is there a way to look at previous posts that you have made? I keep having difficulties finding my old posts.