如何在“x”后面插入换行符人物

发布于 2024-11-03 19:20:21 字数 371 浏览 1 评论 0原文

我目前正在开发一个新闻广播图形程序,该程序使用 Visual Basic 编写脚本。我的挑战是这样的:

我有一个 .xml 文件,其中包含多条数据,其中一条数据需要添加到图形(我们网站的新闻标题)中。然而,这些标题对于图形来说太长,需要添加换行符。我已经通过图形软件的其余部分成功地将这个标题添加到脚本中,它的 temp.txt 名称是 BodyTxt(i).Text (其中 (i) 是脚本另一部分循环的一部分,但会始终等于 1、2 或 3)。 35 个字符后,我需要换行。做到这一点最简单的方法是什么?

为了供将来参考,我可以看到它被用来在网页中创建类似的脚本,以便自动从 RSS 或 .xml 提要填充数据字段,而不会破坏模板,也不会强制字体缩小以适合整个页面字段,或在单词中间创建换行符。

I'm currenty working on a newscast graphics program that is using Visual Basic for scripting. My challenge is this:

I have a .xml file that contains several pieces of data within it, one of which needs to be added to the graphic (a news headline from our website). These headlines are too long for the graphic, however, and need a line break added to them. I have successfully gotten this headline into the script through the rest of the graphics software, and it's temp.txt name is BodyTxt(i).Text (where (i) is a part of a loop for another part of the script, but will always equal 1, 2, or 3). After 35 characters, I need a line break. What would be the simplest way of doing this?

For future reference, I could see this being used in order to create a similar script within a web page in order to automatically populate data fields from an RSS or .xml feed without breaking the template and either forcing a font to shrink to fit the entire field, or creating a line break in the middle of a word.

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

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

发布评论

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

评论(1

摘星┃星的人 2024-11-10 19:20:21

这是您要找的吗?


Sub Main()
    Dim testMessage As String

    testMessage = "For future reference, I could see this being used in order to create a similar script within a web page in order to automatically populate data fields from an RSS or .xml feed without breaking the template and either forcing a font to shrink to fit the entire field, or creating a line break in the middle of a word."

    PrintMessage(testMessage, 30)

    Console.ReadLine()
End Sub

Sub PrintMessage(Message As String, Length As Integer)
    Dim currentLength = 0

    Dim words As Array

    words = Split(Message, " ")

    For Each word As String In words
        If currentLength + word.Length > Length Then
            Console.Write(ControlChars.Tab & currentLength)                                         
            Console.WriteLine()
            currentLength = 0
        End If

        Console.Write(word & " ")
        currentLength += word.Length
    Next
        Console.Write(ControlChars.Tab & currentLength)
End Sub 

产生以下输出:

For future reference, I could see     28
this being used in order to create a  29
similar script within a web page in   29
order to automatically populate       28
data fields from an RSS or .xml feed  29
without breaking the template and     29
either forcing a font to shrink to    28
fit the entire field, or creating a   29
line break in the middle of a word.   29

Is this what you're looking for?


Sub Main()
    Dim testMessage As String

    testMessage = "For future reference, I could see this being used in order to create a similar script within a web page in order to automatically populate data fields from an RSS or .xml feed without breaking the template and either forcing a font to shrink to fit the entire field, or creating a line break in the middle of a word."

    PrintMessage(testMessage, 30)

    Console.ReadLine()
End Sub

Sub PrintMessage(Message As String, Length As Integer)
    Dim currentLength = 0

    Dim words As Array

    words = Split(Message, " ")

    For Each word As String In words
        If currentLength + word.Length > Length Then
            Console.Write(ControlChars.Tab & currentLength)                                         
            Console.WriteLine()
            currentLength = 0
        End If

        Console.Write(word & " ")
        currentLength += word.Length
    Next
        Console.Write(ControlChars.Tab & currentLength)
End Sub 

Produces this output:

For future reference, I could see     28
this being used in order to create a  29
similar script within a web page in   29
order to automatically populate       28
data fields from an RSS or .xml feed  29
without breaking the template and     29
either forcing a font to shrink to    28
fit the entire field, or creating a   29
line break in the middle of a word.   29
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文