Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6771093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:23:28+00:00 2026-05-26T15:23:28+00:00

MVC 3. Vb.net. Part of my app generates PDF files using Itextsharp. Some strings

  • 0

MVC 3. Vb.net. Part of my app generates PDF files using Itextsharp. Some strings are too long to go onto the background image correctly. So I basically need to split this string when its over 26 characters long and when it splits it cant split in the middle of a word. from there I will use newline to add the string to the right to the next line… Any ideas that might point me in the right direction.. I did start bulding the function that I will pass the string into test for length and then pass back the string after it finishes but I am stummped after that..

    Private Function stringLength(ByVal _string As String) As String
        If _string.Length < 26 Then
            _string.Split(
        End If
    End Function
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:23:29+00:00Added an answer on May 26, 2026 at 3:23 pm

    I’m sure there’s a million different ways to do this.

    You basically need to get all of your words split by the space into a list. After that, you just need to keep checking if the current word plus a space plus the next word reach your threshold or not, and if it does, you move to the next line. Once you have all of your lines, then you rejoin the list into a single string again.

    Private Function LimitWidth(ByVal text As String, ByVal maxCharacters As Integer) As String
      Dim words As List(Of String) = text.Split(" "c).ToList()
    
      If text.Length < maxCharacters OrElse words.Count = 1 Then
        Return text
      Else
        Dim lines As New List(Of String)
    
        Dim currentLine As String = words(0)
        For i As Integer = 1 To words.Count - 1
          If (currentLine & " " & words(i)).Length > maxCharacters Then
            lines.Add(currentLine)
            currentLine = words(i)
    
            If i = words.Count - 1 Then
              lines.Add(currentLine)
            End If
          Else
            If i = words.Count - 1 Then
              lines.Add(currentLine & " " & words(i))
            End If
    
            currentLine &= " " & words(i)
          End If
        Next
    
        Return String.Join(Environment.NewLine, lines.ToArray())
      End If
    End Function
    

    To Test:

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
      MessageBox.Show(LimitWidth("This is a really long sentence " & _
                                 "meant to demonstrate how to split " & _
                                 "the words into a confined character length.", 26))
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My ASP.NET MVC application is a small part of a bigger ColdFusion app that
My ASP.NET MVC web app requires the upload of image files. These image files
In my asp.net mvc app i am using the activedirectorymembershipprovider. In the active directory
HI all, I am using Entity Framework and ASP.NET MVC 3. In one part
Is it part of Asp.Net MVC 2.0. If not then does Asp.Net MVC 2.0
I have an ASP.NET MVC application that has one part where I dont really
Does MVC.NET handle Roles using cookies, or does a controller check with the Role
I have a VS 2008, .NET 3.5 targeted MVC.NET app. I am developing on
I am using jQuery 1.7.1 and jQuery maskedinput 1.3 in my ASP.NET MVC 3
A system is to have an ASP.Net MVC back-end. Part of the UI will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.