logo
down
shadow

display a string with multiple lines in TextBox


display a string with multiple lines in TextBox

By : johnwoo
Date : November 22 2020, 03:03 PM
will help you Use TextBox.Multiline Property
Refer this
code :


Share : facebook icon twitter icon
Read from a Text File only lines which starts with a specific string and display them in a form TextBox. (C#)

Read from a Text File only lines which starts with a specific string and display them in a form TextBox. (C#)


By : user3504479
Date : March 29 2020, 07:55 AM
I hope this helps you . I want to read some specific information from a .txt file and display that particular lines inside a TextBox in a form application. The .txt file template looks like this: , In this case you should use String.StartsWith
Example:
code :
using (var reader = new System.IO.StreamReader(@"C:\file.txt"))
{
    while (!reader.EndOfStream)
    {
        var line = reader.ReadLine();

        if (line.StartsWith("info"))
        {
            // do something
        }
    }

    reader.Close();
}
How to format a String to display on multiple Lines

How to format a String to display on multiple Lines


By : Queenie
Date : March 29 2020, 07:55 AM
With these it helps Here i have a message string that displays the content of an email. I would like the From, The subject and the body to all display on a new line. , If email is in html format then try
c# 10 textbox to display array items, 30 lines in each textbox, separated with comma

c# 10 textbox to display array items, 30 lines in each textbox, separated with comma


By : Prem Chand
Date : March 29 2020, 07:55 AM
With these it helps I have 10 different textbox control and a textfile upload script on a button click. I want that when a user uploads a textfile which probably will consist 300 lines, it gets divided into 10 different textbox, 30 lines in each textbox, where each line separated with comma. I have used array to store textfile items. , Here is some code you can use for that, an explanation follows:
code :
string[] text = System.IO.File.ReadAllLines(file);
var thirtyLineSections = text
    .Select((line, index) => new { line, group = index / 30 })
    .GroupBy(item => item.group)
    .ToArray();
int textboxIndex = 0;
foreach (var section in thirtyLineSections)
{
    string textForSection = string.Join(",",
        section.Select(item => item.line).ToArray()); // see note below
    textboxes[textboxIndex].Text = textForSection;
    textboxIndex++;
}
section.Select(item => item.line));
original file     with index          after dividing by 30
line 1            0,line 1            0,line 1
line 2            1,line 2            0,line 2
line 3            2,line 3            0,line 3
some text         3,some text         0,some text
line 5            4,line 5            0,line 5
...
line 30           29,line 30          0,line 30
line 31           30,line 31          1,line 31
var textboxes = new[]
{
    textbox1,
    textbox2,
    ...
    textboxN
};
string[] text = System.IO.File.ReadAllLines(file);
var thirtyLineSections = new List<List<string>>();
List<string> currentList = null;
foreach (string line in text)
{
    if (currentList == null)
    {
        currentList = new List<string>();
        thirtyLineSections.Add(currentList);
    }
    currentList.Add(line);
    if (currentList.Count == 30)
        currentList = null;
}

foreach (var section in thirtyLineSections)
{
    string.Join(",", section).Dump();
}
Crop last N lines of a string to display in userform textbox

Crop last N lines of a string to display in userform textbox


By : UnknownMan
Date : March 29 2020, 07:55 AM
it fixes the issue You can use this function to return only the last N lines of a string, and then display that in your textbox.
Note that you have to specify what the line break character is. Depending on your specific application, it could be vbCrLf, vbCr, vbLf, or even some other delimiter.
code :
Function GetLastLines(ByVal s As String, ByVal nLinesToDisplay As Long, _
    Optional ByVal lineBreakChar As String = vbCrLf)

    'Split the string into an array
    Dim splitString() As String
    splitString = Split(s, lineBreakChar)

    'How many lines are there?
    Dim nLines As Long
    nLines = UBound(splitString) + 1

    If nLines <= nLinesToDisplay Then
        'No need to remove anything. Get out.
        GetLastLines = s
        Exit Function
    End If

    'Collect last N lines in a new array
    Dim lastLines() As String
    ReDim lastLines(0 To nLinesToDisplay - 1)
    Dim i As Long
    For i = 0 To UBound(lastLines)
        lastLines(i) = splitString(i + nLines - nLinesToDisplay)
    Next i

    'Join the lines array into a single string
    GetLastLines = Join(lastLines, lineBreakChar)
End Function
MsgBox GetLastLines( _
    "line 1" & vbCrLf & "line 2" & vbCrLf & "line 3" & vbCrLf _
        & "line 4" & vbCrLf & "line 5" & vbCrLf & "line 6", _
    4, vbCrLf)
Function GetLastLines2(ByVal s As String, ByVal nLinesToDisplay As Long, _
    Optional ByVal lineBreakChar As String = vbCrLf)

    'An arbitrary character that will never be in your input string:
    Dim delim As String: delim = Chr(1)

    'How many lines are there?
    Dim nLines As Long
    nLines = UBound(Split(s, lineBreakChar)) + 1

    If nLines <= nLinesToDisplay Then
        'No need to remove anything. Get out.
        GetLastLines2 = s
        Exit Function
    End If

    'Replace one line break with delim, split the string on it, 
    'return only second part:
    GetLastLines2 = Split( _
        WorksheetFunction.Substitute( _
            s, lineBreakChar, delim, nLines - nLinesToDisplay), _
        delim)(1)

End Function
How to display a string of integers on multiple lines?

How to display a string of integers on multiple lines?


By : Clancy Fort
Date : March 29 2020, 07:55 AM
this will help Use string.Join to create one string out of your numbers string (a string is a collection of characters so you can do so), and specify the separator as Environment.NewLine:
code :
var result = string.Join(Environment.NewLine, even.AsEnumerable());
var even = string.Join(Environment.NewLine, inputData.Select(c => c % 2 == 0));
Related Posts Related Posts :
  • ApiController vs ODataController when exposing DTOs
  • Is there a benefit to breaking up Integration tests with TestCategory?
  • Implementing a scalable node.js-like HTTP server with c# and .net
  • Call GC.Collect before memory hungry unmanaged function?
  • SQL Server no source code, wanting to change the connection string
  • Multiple partials means that model errors bleed between forms
  • Easiest way to extract 4 digit number out of string?
  • What is the point of 'FieldSpecified' in WCF?
  • Search and replace with regex including lookbehinds does not work in VS2017
  • How to Quit or Close (not Kill) Word document (process)?
  • Parsing string with nested separators
  • How to invoke a DLL method from PowerShell 1.0
  • Starting Web Api 2 with OWIN
  • Is it possible to programmatically get a shared Dropbox link without sending the user to the dropbox login page?
  • HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\TimeZoneKeyName corrupt?
  • Performance cost of creating array of constants as function argument
  • SQL Server rowversion and order
  • Type.GetType returns null when called via COM interop
  • Is the Microsoft.Practices.EnterpriseLibrary.Validation outdated?
  • .net Bitmap changes color of image
  • vb.net reading text file ,split to random range
  • LINQ Join with same Name on different tables
  • Programmatically share a dropbox link in .net without having user login to Dropbox
  • bootstrapper fails to install .Net Framework 4.0
  • Why would signing credentials from a RSA-SHA512 X509Certificate2 appear to be RSA-SHA256?
  • Using .NET Class as the DataSource with SSRS RDLC
  • Choosing SQL Server version for new project
  • WCF FileNotFoundException
  • Fullcalendar ignoring all options on initialization?
  • Freebase oAuth2 Bad Request(400) .Net
  • Why does InlineCollection not offer an Indexer (without casting)?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org