替换 .NET 字符串中的 Oracle 换行符

发布于 2024-11-03 21:23:50 字数 1703 浏览 1 评论 0原文

我使用 Oracle 命令 dbms_output.get_line 从存储过程中检索输出。一旦我的代码运行该命令,我将通过 32000 字节长的缓冲区字符串检索结果。

不可避免地,该字符串将包含 Oracle 换行符 (chr(10) 和 chr(13)),我想将其替换为 Environment.NewLine,这样我就可以在标准 Winforms 文本框中显示输出。

这是我一直在使用的代码 - 我现在不记得从哪里得到 Oracle 命令,但如果我找到它,我会添加链接。

Dim cmdGetOutput As New OracleCommand("declare " & _
" l_line varchar2(255); " & _
" l_done number; " & _
" l_buffer long; " & _
"begin " & _
" loop " & _
" exit when length(l_buffer)+255 > :maxbytes OR l_done =1; " & _
" dbms_output.get_line( l_line, l_done ); " & _
" l_buffer := l_buffer || l_line || chr(10); " & _
" end loop; " & _
" :done := l_done; " & _
" :buffer := l_buffer; " & _
"end;", cnOracle)

cmdGetOutput.Parameters.Add("maxbytes", OracleType.Int16)
cmdGetOutput.Parameters("maxbytes").Value = 32000
cmdGetOutput.Parameters.Add("done", OracleType.Int16)
cmdGetOutput.Parameters("done").Direction = ParameterDirection.Output
cmdGetOutput.Parameters.Add("buffer", OracleType.LongVarChar, 32000)
cmdGetOutput.Parameters("buffer").Direction = ParameterDirection.Output

Dim strOutput As List(Of String) = New List(Of String)
Dim intStatus As Integer = 0
Try
   While True
      cmdGetOutput.ExecuteNonQuery()
      strOutput.Add(cmdGetOutput.Parameters("buffer").Value)
      If cmdGetOutput.Parameters("done").Value = 1 Then
         Exit While
      End If
   End While
Catch ex As Exception
   MsgBox(ex.Message)
Finally
   For ixLines as Integer = 0 to strOutput.Count - 1
      txtOutput.Text = txtOutput.Text & strOutput(ixLines)
   Next
End Try

当我运行此命令时,txtOutput 将在换行符所在的位置包含框字符。

谢谢大家的帮助!

I'm using the Oracle command dbms_output.get_line to retrieve output from a stored procedure. Once my code runs the command, I'm retrieving the results through a buffer string, 32000 bytes long.

Inevitably, this string will have Oracle line breaks (chr(10) and chr(13)) in it that I'd like to replace with Environment.NewLine so I can display the output in a standard Winforms textbox.

Here is the code I've been using - I don't recall exactly where I got the Oracle command right now, but if I find it, I'll add the link.

Dim cmdGetOutput As New OracleCommand("declare " & _
" l_line varchar2(255); " & _
" l_done number; " & _
" l_buffer long; " & _
"begin " & _
" loop " & _
" exit when length(l_buffer)+255 > :maxbytes OR l_done =1; " & _
" dbms_output.get_line( l_line, l_done ); " & _
" l_buffer := l_buffer || l_line || chr(10); " & _
" end loop; " & _
" :done := l_done; " & _
" :buffer := l_buffer; " & _
"end;", cnOracle)

cmdGetOutput.Parameters.Add("maxbytes", OracleType.Int16)
cmdGetOutput.Parameters("maxbytes").Value = 32000
cmdGetOutput.Parameters.Add("done", OracleType.Int16)
cmdGetOutput.Parameters("done").Direction = ParameterDirection.Output
cmdGetOutput.Parameters.Add("buffer", OracleType.LongVarChar, 32000)
cmdGetOutput.Parameters("buffer").Direction = ParameterDirection.Output

Dim strOutput As List(Of String) = New List(Of String)
Dim intStatus As Integer = 0
Try
   While True
      cmdGetOutput.ExecuteNonQuery()
      strOutput.Add(cmdGetOutput.Parameters("buffer").Value)
      If cmdGetOutput.Parameters("done").Value = 1 Then
         Exit While
      End If
   End While
Catch ex As Exception
   MsgBox(ex.Message)
Finally
   For ixLines as Integer = 0 to strOutput.Count - 1
      txtOutput.Text = txtOutput.Text & strOutput(ixLines)
   Next
End Try

When I run this, txtOutput will have box characters in places where newlines should be.

Thanks for the help, everyone!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情定在深秋 2024-11-10 21:23:50

首先,该代码甚至不应该编译。您不能将 List(of String) 分配给 TextBox.Text 属性。

其次,String 类定义了 Replace(searchstring, replacementstring) 方法。

first off, that code shouldn't even compile. You can not assign a List(of String) to a TextBox.Text property.

second, the String class defines a Replace(searchstring, replacementstring) method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文