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. Shorter form of a String

Shorter form of a String

Scheduled Pinned Locked Moved C#
help
9 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
    shafiullah123
    wrote on last edited by
    #1

    Hi Folks, I have a string.."Desktop Development Web Development Multimedia Development". Now i want a 20 character string "Desk Dev Web Dev" like this...pls help

    X D 2 Replies Last reply
    0
    • S shafiullah123

      Hi Folks, I have a string.."Desktop Development Web Development Multimedia Development". Now i want a 20 character string "Desk Dev Web Dev" like this...pls help

      X Offline
      X Offline
      Xmen Real
      wrote on last edited by
      #2

      split the string with ' '(space char, e.g. string.split(' ')) and then iterate all the splitted parts, rip first 3 or 4 chars by using string.Substring() plus keep append a main string.

      TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

      G 1 Reply Last reply
      0
      • S shafiullah123

        Hi Folks, I have a string.."Desktop Development Web Development Multimedia Development". Now i want a 20 character string "Desk Dev Web Dev" like this...pls help

        D Offline
        D Offline
        dan sh
        wrote on last edited by
        #3

        If you need first three characters of each word, then you use Split and Substring. In the example you gave, you have taken "Desk" from desktop ie 4 characters and 3 characters from others. The number of characters to be taken from a word is not fixed. It depends on the word. Now if the string changes to say "Development Web Development Multimedia Development". How do you want this to be divided?

        Time is the best teacher; unfortunately it kills all of its students. जय हिंद

        1 Reply Last reply
        0
        • X Xmen Real

          split the string with ' '(space char, e.g. string.split(' ')) and then iterate all the splitted parts, rip first 3 or 4 chars by using string.Substring() plus keep append a main string.

          TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          There's a one-liner for everything. ;)

          words = string.Join(" ", words.Split().Select(s => s.Substring(0, 3)).ToArray());

          Despite everything, the person most likely to be fooling you next is yourself.

          X 1 Reply Last reply
          0
          • G Guffa

            There's a one-liner for everything. ;)

            words = string.Join(" ", words.Split().Select(s => s.Substring(0, 3)).ToArray());

            Despite everything, the person most likely to be fooling you next is yourself.

            X Offline
            X Offline
            Xmen Real
            wrote on last edited by
            #5

            Guffa wrote:

            words = string.Join(" ", words.Split().Select(s => s.Substring(0, 3)).ToArray());

            :wtf: :wtf: When did Microsoft put Select() in string.Split():confused:

            TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

            G 1 Reply Last reply
            0
            • X Xmen Real

              Guffa wrote:

              words = string.Join(" ", words.Split().Select(s => s.Substring(0, 3)).ToArray());

              :wtf: :wtf: When did Microsoft put Select() in string.Split():confused:

              TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

              G Offline
              G Offline
              Guffa
              wrote on last edited by
              #6

              Xmen wrote:

              When did Microsoft put Select() in string.Split()

              Never. It's an extension method, and it's in the IEnumerable<T> class.

              Despite everything, the person most likely to be fooling you next is yourself.

              X 1 Reply Last reply
              0
              • G Guffa

                Xmen wrote:

                When did Microsoft put Select() in string.Split()

                Never. It's an extension method, and it's in the IEnumerable<T> class.

                Despite everything, the person most likely to be fooling you next is yourself.

                X Offline
                X Offline
                Xmen Real
                wrote on last edited by
                #7

                so its a LINQ thing, listen mate. I use .Net Framework 2.0 usually as most of users do not have 3.0(+).

                TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

                G 1 Reply Last reply
                0
                • X Xmen Real

                  so its a LINQ thing, listen mate. I use .Net Framework 2.0 usually as most of users do not have 3.0(+).

                  TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

                  G Offline
                  G Offline
                  Guffa
                  wrote on last edited by
                  #8

                  Listen mate, it's just a one-liner. If you don't understand it, it only means that you have more to learn...

                  Despite everything, the person most likely to be fooling you next is yourself.

                  X 1 Reply Last reply
                  0
                  • G Guffa

                    Listen mate, it's just a one-liner. If you don't understand it, it only means that you have more to learn...

                    Despite everything, the person most likely to be fooling you next is yourself.

                    X Offline
                    X Offline
                    Xmen Real
                    wrote on last edited by
                    #9

                    there was nothing that I couldn't understand. After all I know how to use google ;)

                    TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

                    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