I was just wondering if there is a possible way to get the last 4 characters from a label or textbox. If someone could please provide me with an example that would be great!

Thanks..

Recommended Answers

Use SubString method. Click Here

Jump to Post

The answer is Substring

Jump to Post

All 7 Replies

Use this code:

  Dim str As String = "abcd1234"
            MsgBox(str.Substring(Math.Max(0, str.Length - 4)))       

Use SubString method. Click Here

The answer is Substring

@ khair.ullah: What about str.Substring(str.Length - 4) ?

use like this :

 Dim str As String
        str = TextBox1.Text.Substring(Math.Max(0, TextBox1.Text.Length - 4))
        MsgBox(str)
use like this :

 Dim str As String
        str = TextBox1.Text.Substring(Math.Max(0, TextBox1.Text.Length - 4))
        MsgBox(str)

That seems to work. Thanks guys... :D

Yeah, this also works:

str.Substring((Math.Max(0, (str.Length - 4) * Convert.ToInt32( Math.Sin( 4.0 * Math.Atan(1.0) / 2)))))

What is wrong with:

str.Substring(str.Length - 4)

This also does the job.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.