Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. best way to read string

best way to read string

Scheduled Pinned Locked Moved C#
c++tutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cppdotnet
    wrote on last edited by
    #1

    I have this number from which I have to read first few number depending on another number. What is the best way to do that. For example ... NumToread = 3 , number = "4567889465" answer should newNum = 456 i can do that using for (int i=1;i<=NumToread ;i++) does any one knows better way ... As you can say .. I am very new to programming Thanks CPP Thanks

    J 1 Reply Last reply
    0
    • C cppdotnet

      I have this number from which I have to read first few number depending on another number. What is the best way to do that. For example ... NumToread = 3 , number = "4567889465" answer should newNum = 456 i can do that using for (int i=1;i<=NumToread ;i++) does any one knows better way ... As you can say .. I am very new to programming Thanks CPP Thanks

      J Offline
      J Offline
      Joshua Quick
      wrote on last edited by
      #2

      You should use the String.Substring() method. int numToRead = 3; string buf = "123456789"; buf = buf.Substring(0, 3); // buf now = "123"

      C 1 Reply Last reply
      0
      • J Joshua Quick

        You should use the String.Substring() method. int numToRead = 3; string buf = "123456789"; buf = buf.Substring(0, 3); // buf now = "123"

        C Offline
        C Offline
        cppdotnet
        wrote on last edited by
        #3

        Thanks :) Thanks

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups