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
  1. Home
  2. General Programming
  3. C#
  4. achive to characters in a string in an other way [modified :D]

achive to characters in a string in an other way [modified :D]

Scheduled Pinned Locked Moved C#
questiondatabase
7 Posts 4 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.
  • S Offline
    S Offline
    Sajjad Izadi
    wrote on last edited by
    #1

    hi friends, as you know, when you initialize a String, you can achive the characters by:

    String str = "hello";
    char character = str[0]; //or str[int index]

    but i want to achive to the character without using any methods or facilities prepared in String class. how can i write a method to achive? thanks

    modified on Sunday, June 29, 2008 1:36 PM

    N E M 3 Replies Last reply
    0
    • S Sajjad Izadi

      hi friends, as you know, when you initialize a String, you can achive the characters by:

      String str = "hello";
      char character = str[0]; //or str[int index]

      but i want to achive to the character without using any methods or facilities prepared in String class. how can i write a method to achive? thanks

      modified on Sunday, June 29, 2008 1:36 PM

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      Sajjad Izadi wrote:

      int charPosition = str[0]; //or str[int index]

      it returns a char. Your example will show the ascii value of the character at the supplied index and not the character.

      Sajjad Izadi wrote:

      but i want to achive to the character without using any methods or facilities prepared in String class. how can i write a method to achive?

      Looks like someone asked you this for an interview ? You can iterate though the string like this

      foreach (char c in str)
      {
      Console.WriteLine(c);
      }

      All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

      S 1 Reply Last reply
      0
      • N N a v a n e e t h

        Sajjad Izadi wrote:

        int charPosition = str[0]; //or str[int index]

        it returns a char. Your example will show the ascii value of the character at the supplied index and not the character.

        Sajjad Izadi wrote:

        but i want to achive to the character without using any methods or facilities prepared in String class. how can i write a method to achive?

        Looks like someone asked you this for an interview ? You can iterate though the string like this

        foreach (char c in str)
        {
        Console.WriteLine(c);
        }

        All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

        S Offline
        S Offline
        Sajjad Izadi
        wrote on last edited by
        #3

        oh excuse me :) you are right, it returns a char. but i don't want to use 'foreach', too. i want it for something like an interview :-D. thanks again

        modified on Sunday, June 29, 2008 3:15 PM

        N 1 Reply Last reply
        0
        • S Sajjad Izadi

          oh excuse me :) you are right, it returns a char. but i don't want to use 'foreach', too. i want it for something like an interview :-D. thanks again

          modified on Sunday, June 29, 2008 3:15 PM

          N Offline
          N Offline
          N a v a n e e t h
          wrote on last edited by
          #4

          I don't think that there is a way without using anything related to string class. I am not sure though.

          All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

          1 Reply Last reply
          0
          • S Sajjad Izadi

            hi friends, as you know, when you initialize a String, you can achive the characters by:

            String str = "hello";
            char character = str[0]; //or str[int index]

            but i want to achive to the character without using any methods or facilities prepared in String class. how can i write a method to achive? thanks

            modified on Sunday, June 29, 2008 1:36 PM

            E Offline
            E Offline
            engsrini
            wrote on last edited by
            #5

            How about this

            string str = "hello";
            char[] c = System.Text.ASCIIEncoding.Unicode.GetChars(
            System.Text.ASCIIEncoding.Unicode.GetBytes ((str)));

            S 1 Reply Last reply
            0
            • S Sajjad Izadi

              hi friends, as you know, when you initialize a String, you can achive the characters by:

              String str = "hello";
              char character = str[0]; //or str[int index]

              but i want to achive to the character without using any methods or facilities prepared in String class. how can i write a method to achive? thanks

              modified on Sunday, June 29, 2008 1:36 PM

              M Offline
              M Offline
              Mark Churchill
              wrote on last edited by
              #6

              If this is the interview question where you have to reverse a string, or ToUpper it or something like that without "using any built in methods" then you can assume you are able to use the char this[int] indexer. Good luck.

              Mark Churchill Director Dunn & Churchill Free Download:
              Diamond Binding: The simple, powerful, reliable, and effective data layer toolkit for Visual Studio.

              1 Reply Last reply
              0
              • E engsrini

                How about this

                string str = "hello";
                char[] c = System.Text.ASCIIEncoding.Unicode.GetChars(
                System.Text.ASCIIEncoding.Unicode.GetBytes ((str)));

                S Offline
                S Offline
                Sajjad Izadi
                wrote on last edited by
                #7

                i'll test it, 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