Question

How do I convert the following VB WinForm to C# WPF?

txtFoo.Text = Strings.Right(txtFoo.Text, 10000)

I cannot find Strings in WPF control class and String in WPF does not have method of String.Right

Was it helpful?

Solution

You could try this:

 txtFoo.Text = txtFoo.Text.Substring(txtFoo.Text.Length - 10000); 

Of course you need to check if the length of the string is greater than 10000

OTHER TIPS

It is a VB.NET convenience method. Project + Add Reference, select Microsoft.VisualBasic and put

using Microsoft.VisualBasic;

at the top of your source code file.

A C# version of that same code would look like this:

    if (txtFoo.Text.Length > 10000) {
        txtFoo.Text = txtFoo.Text.Substring(txtFoo.Text.Length - 10000);
    }

This has nothing to do with WinForms. You can use that method just fine. Just reference Microsoft.VisualBasic and add a using directive to the same thing.

You certainly can replace it with System.String calls. But it's fine to use that assembly from C# if you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top