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. How to remove character from string

How to remove character from string

Scheduled Pinned Locked Moved C#
tutorialquestion
17 Posts 8 Posters 1 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.
  • M Offline
    M Offline
    M Riaz Bashir
    wrote on last edited by
    #1

    Hi, Kindly let me know, How may I remove character from string value? Example: string strValue = "AP.P.LE"; // "APPLE" I want to remove dots only Thank you (Riaz)

    R C A N 4 Replies Last reply
    0
    • M M Riaz Bashir

      Hi, Kindly let me know, How may I remove character from string value? Example: string strValue = "AP.P.LE"; // "APPLE" I want to remove dots only Thank you (Riaz)

      R Offline
      R Offline
      R Giskard Reventlov
      wrote on last edited by
      #2

      strValue.Replace(".", string.Empty); is one way.

      "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me

      1 Reply Last reply
      0
      • M M Riaz Bashir

        Hi, Kindly let me know, How may I remove character from string value? Example: string strValue = "AP.P.LE"; // "APPLE" I want to remove dots only Thank you (Riaz)

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

        Try Replace method, and replace your dots (.) with string.Empty ("").

        R 1 Reply Last reply
        0
        • C Calla

          Try Replace method, and replace your dots (.) with string.Empty ("").

          R Offline
          R Offline
          R Giskard Reventlov
          wrote on last edited by
          #4

          If someone has already answered why post exactly the same answer??? :mad:

          "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me

          C J P P 4 Replies Last reply
          0
          • R R Giskard Reventlov

            If someone has already answered why post exactly the same answer??? :mad:

            "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me

            C Offline
            C Offline
            Calla
            wrote on last edited by
            #5

            Why write a rude reply to someone who also tries to help out just because the answer is almost the same? Obviously I had not seen your reply when I wrote mine.. and really, what is your problem? :wtf:

            R 1 Reply Last reply
            0
            • R R Giskard Reventlov

              If someone has already answered why post exactly the same answer??? :mad:

              "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me

              J Offline
              J Offline
              J4amieC
              wrote on last edited by
              #6

              They were 3 minutes apart dude... I ofen have a page open for that sort of time without a refresh to see if other posts have been made. Your comment would have been fine if there was 3 hrs, but 3 minutes... give a little grace.

              1 Reply Last reply
              0
              • C Calla

                Why write a rude reply to someone who also tries to help out just because the answer is almost the same? Obviously I had not seen your reply when I wrote mine.. and really, what is your problem? :wtf:

                R Offline
                R Offline
                R Giskard Reventlov
                wrote on last edited by
                #7

                Calla wrote:

                Obviously I had not seen your reply when I wrote mine

                You would say that, wouldn't you?

                Calla wrote:

                and really, what is your problem?

                You! :-) Okay, okay, sorry - bit pissed because it happen more than it used to: seems like people just trying to get rep points for no good reason.

                "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me

                C 1 Reply Last reply
                0
                • R R Giskard Reventlov

                  Calla wrote:

                  Obviously I had not seen your reply when I wrote mine

                  You would say that, wouldn't you?

                  Calla wrote:

                  and really, what is your problem?

                  You! :-) Okay, okay, sorry - bit pissed because it happen more than it used to: seems like people just trying to get rep points for no good reason.

                  "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me

                  C Offline
                  C Offline
                  Calla
                  wrote on last edited by
                  #8

                  digital man wrote:

                  You would say that, wouldn't you?

                  Like J4amieC wrote: They were 3 minutes apart dude...

                  digital man wrote:

                  Okay, okay, sorry - bit pissed because it happen more than it used to: seems like people just trying to get rep points for no good reason.

                  Yes.. getting rep points is really what life is all about, isn't it? ;)

                  R 1 Reply Last reply
                  0
                  • C Calla

                    digital man wrote:

                    You would say that, wouldn't you?

                    Like J4amieC wrote: They were 3 minutes apart dude...

                    digital man wrote:

                    Okay, okay, sorry - bit pissed because it happen more than it used to: seems like people just trying to get rep points for no good reason.

                    Yes.. getting rep points is really what life is all about, isn't it? ;)

                    R Offline
                    R Offline
                    R Giskard Reventlov
                    wrote on last edited by
                    #9

                    Calla wrote:

                    Like J4amieC wrote: They were 3 minutes apart dude...

                    That's a lifetime.

                    Calla wrote:

                    Yes.. getting rep points is really what life is all about, isn't it?

                    For me, no, for you... I think there are people here who see them as important though I can't see why.

                    "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me

                    1 Reply Last reply
                    0
                    • R R Giskard Reventlov

                      If someone has already answered why post exactly the same answer??? :mad:

                      "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me

                      P Offline
                      P Offline
                      Pete OHanlon
                      wrote on last edited by
                      #10

                      I've occassionally done this when I've come to one of the forums, got distracted by a task (having possibly started an answer off), and not refreshed the browser. It has nothing to do with attempting to gain rep points (I don't really need to boost mine), and more to do with timing.

                      "WPF has many lovers. It's a veritable porn star!" - Josh Smith

                      As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

                      My blog | My articles | MoXAML PowerToys | Onyx

                      1 Reply Last reply
                      0
                      • M M Riaz Bashir

                        Hi, Kindly let me know, How may I remove character from string value? Example: string strValue = "AP.P.LE"; // "APPLE" I want to remove dots only Thank you (Riaz)

                        A Offline
                        A Offline
                        Abhinav S
                        wrote on last edited by
                        #11

                        Try something like string s=Regex.Replace(,"[^\\w\\.@-]","");.

                        The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.

                        1 Reply Last reply
                        0
                        • M M Riaz Bashir

                          Hi, Kindly let me know, How may I remove character from string value? Example: string strValue = "AP.P.LE"; // "APPLE" I want to remove dots only Thank you (Riaz)

                          N Offline
                          N Offline
                          NileshUpadhyay
                          wrote on last edited by
                          #12

                          Hi Riaz, you can remove "." from a given string from the following ways: 1) Simple way :

                          string strValue = "This. is .test .string. that. removes the (DOT) from the. string";
                          strValue = strValue.Replace(".",string.Empty);

                          1. REGEX WAY :

                          string strValue = "This. is .test .string. that. removes the (DOT) from the. string";
                          strValue = System.Text.RegularExpressions.Regex.Replace(strValue, @"\.+", "");

                          please check the value of strValue ( you find that "." is removed from the given string ) 3) Through Loop and replace characters: Here for simplicity I have made a static function that will take input as a string and returns a string by replacing "." NOTE :- To Remove all special characters including white space from the given string just uncomment the first line in below function.

                          public static string RemoveSpecialChars(string str)
                          {
                          //string[] chars = new string[] { ",", ".", "/", "!", "@", "#", "$", "%", "^", "&", "*", "'", "\"", ";", "-", "_", "(", ")", ":", "|", "[", "]", " " };
                          string[] chars = new string[] { "." };
                          for (int i = 0; i < chars.Length; i++)
                          {
                          if (str.Contains(chars[i]))
                          {
                          str = str.Replace(chars[i], "");
                          }
                          }
                          return str;
                          }

                          Now use this function anywhere to remove "." from input string . Please check below example for how to use :

                          string strValue = "This. is .test .string. that. removes the (DOT) from the. string";
                          strValue = RemoveSpecialChars(strValue );

                          please check the value of strValue ( you find that "." is removed from the given string ) Note :- If your purpose is to remove "." only from a given string then Simple Way is better.But If you want special characters to be removed from string then you either need REGEX or Through Loop and replace characters. For REGEX you have to find the REGEX to remove special characters. Thanks, Nilesh Upadhyay

                          J P 2 Replies Last reply
                          0
                          • N NileshUpadhyay

                            Hi Riaz, you can remove "." from a given string from the following ways: 1) Simple way :

                            string strValue = "This. is .test .string. that. removes the (DOT) from the. string";
                            strValue = strValue.Replace(".",string.Empty);

                            1. REGEX WAY :

                            string strValue = "This. is .test .string. that. removes the (DOT) from the. string";
                            strValue = System.Text.RegularExpressions.Regex.Replace(strValue, @"\.+", "");

                            please check the value of strValue ( you find that "." is removed from the given string ) 3) Through Loop and replace characters: Here for simplicity I have made a static function that will take input as a string and returns a string by replacing "." NOTE :- To Remove all special characters including white space from the given string just uncomment the first line in below function.

                            public static string RemoveSpecialChars(string str)
                            {
                            //string[] chars = new string[] { ",", ".", "/", "!", "@", "#", "$", "%", "^", "&", "*", "'", "\"", ";", "-", "_", "(", ")", ":", "|", "[", "]", " " };
                            string[] chars = new string[] { "." };
                            for (int i = 0; i < chars.Length; i++)
                            {
                            if (str.Contains(chars[i]))
                            {
                            str = str.Replace(chars[i], "");
                            }
                            }
                            return str;
                            }

                            Now use this function anywhere to remove "." from input string . Please check below example for how to use :

                            string strValue = "This. is .test .string. that. removes the (DOT) from the. string";
                            strValue = RemoveSpecialChars(strValue );

                            please check the value of strValue ( you find that "." is removed from the given string ) Note :- If your purpose is to remove "." only from a given string then Simple Way is better.But If you want special characters to be removed from string then you either need REGEX or Through Loop and replace characters. For REGEX you have to find the REGEX to remove special characters. Thanks, Nilesh Upadhyay

                            J Offline
                            J Offline
                            J4amieC
                            wrote on last edited by
                            #13

                            Now that is posting 2 hrs later just for rep points. :rolleyes:

                            N C 2 Replies Last reply
                            0
                            • J J4amieC

                              Now that is posting 2 hrs later just for rep points. :rolleyes:

                              N Offline
                              N Offline
                              NileshUpadhyay
                              wrote on last edited by
                              #14

                              HI , Thank you for your comment, but I have just seen this question. I am not posting answer for any points in fact I don't even know that How the point system is calculated because I am not an active member to give answer frequently. Sorry if my answer gives wrong information to anyone . My intention was to provide an answer with multiple ways to achieve the stated thing. Thanks, Nilesh

                              1 Reply Last reply
                              0
                              • J J4amieC

                                Now that is posting 2 hrs later just for rep points. :rolleyes:

                                C Offline
                                C Offline
                                Calla
                                wrote on last edited by
                                #15

                                :laugh:

                                1 Reply Last reply
                                0
                                • N NileshUpadhyay

                                  Hi Riaz, you can remove "." from a given string from the following ways: 1) Simple way :

                                  string strValue = "This. is .test .string. that. removes the (DOT) from the. string";
                                  strValue = strValue.Replace(".",string.Empty);

                                  1. REGEX WAY :

                                  string strValue = "This. is .test .string. that. removes the (DOT) from the. string";
                                  strValue = System.Text.RegularExpressions.Regex.Replace(strValue, @"\.+", "");

                                  please check the value of strValue ( you find that "." is removed from the given string ) 3) Through Loop and replace characters: Here for simplicity I have made a static function that will take input as a string and returns a string by replacing "." NOTE :- To Remove all special characters including white space from the given string just uncomment the first line in below function.

                                  public static string RemoveSpecialChars(string str)
                                  {
                                  //string[] chars = new string[] { ",", ".", "/", "!", "@", "#", "$", "%", "^", "&", "*", "'", "\"", ";", "-", "_", "(", ")", ":", "|", "[", "]", " " };
                                  string[] chars = new string[] { "." };
                                  for (int i = 0; i < chars.Length; i++)
                                  {
                                  if (str.Contains(chars[i]))
                                  {
                                  str = str.Replace(chars[i], "");
                                  }
                                  }
                                  return str;
                                  }

                                  Now use this function anywhere to remove "." from input string . Please check below example for how to use :

                                  string strValue = "This. is .test .string. that. removes the (DOT) from the. string";
                                  strValue = RemoveSpecialChars(strValue );

                                  please check the value of strValue ( you find that "." is removed from the given string ) Note :- If your purpose is to remove "." only from a given string then Simple Way is better.But If you want special characters to be removed from string then you either need REGEX or Through Loop and replace characters. For REGEX you have to find the REGEX to remove special characters. Thanks, Nilesh Upadhyay

                                  P Online
                                  P Online
                                  PIEBALDconsult
                                  wrote on last edited by
                                  #16

                                  For completeness you could also include the Split/Join technique. :-D

                                  1 Reply Last reply
                                  0
                                  • R R Giskard Reventlov

                                    If someone has already answered why post exactly the same answer??? :mad:

                                    "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me

                                    P Online
                                    P Online
                                    PIEBALDconsult
                                    wrote on last edited by
                                    #17

                                    I often take a long time writing a response, doing research to ensure my answer is correct, many people can post while I'm still writing.

                                    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