Splitting number

Welcome Forums General PowerShell Q&A Splitting number

This topic contains 3 replies, has 3 voices, and was last updated by

 
Participant
3 months, 1 week ago.

  • Author
    Posts
  • #104395

    Participant
    Points: 13
    Published
    Rank: Member

    I have a variable

    $t = "4459156205"

    I'm trying to split it into 4459 and 156205

    So I thought I would try

    $t[0..3]

    to get 4459, but I'm getting
    4
    4
    5
    9

    How can I get 4459

  • #104398

    Participant
    Points: 9
    Rank: Member

    You can use the substring method if it's a string ... like this:

    "4459156205".Substring(0,4)
  • #104401

    Participant
    Points: 19
    Rank: Member

    You can also use -join

    -join $t[0..3]
  • #104402

    Participant
    Points: 13
    Published
    Rank: Member

    Thank you

The topic ‘Splitting number’ is closed to new replies.