Click here to Skip to main content
15,893,381 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to remove character from string PinPopular
R. Giskard Reventlov7-Jul-10 22:51
R. Giskard Reventlov7-Jul-10 22:51 
GeneralRe: How to remove character from string Pin
Calla7-Jul-10 22:59
Calla7-Jul-10 22:59 
GeneralRe: How to remove character from string Pin
R. Giskard Reventlov7-Jul-10 23:17
R. Giskard Reventlov7-Jul-10 23:17 
GeneralRe: How to remove character from string Pin
J4amieC7-Jul-10 22:48
J4amieC7-Jul-10 22:48 
GeneralRe: How to remove character from string Pin
Pete O'Hanlon7-Jul-10 23:41
mvePete O'Hanlon7-Jul-10 23:41 
GeneralRe: How to remove character from string Pin
PIEBALDconsult8-Jul-10 3:04
mvePIEBALDconsult8-Jul-10 3:04 
AnswerRe: How to remove character from string Pin
Abhinav S7-Jul-10 23:44
Abhinav S7-Jul-10 23:44 
AnswerRe: How to remove character from string Pin
NileshUpadhyay8-Jul-10 0:29
NileshUpadhyay8-Jul-10 0:29 
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);


2) 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
GeneralRe: How to remove character from string Pin
J4amieC8-Jul-10 0:37
J4amieC8-Jul-10 0:37 
GeneralRe: How to remove character from string Pin
NileshUpadhyay8-Jul-10 0:45
NileshUpadhyay8-Jul-10 0:45 
GeneralRe: How to remove character from string Pin
Calla8-Jul-10 2:27
Calla8-Jul-10 2:27 
GeneralRe: How to remove character from string Pin
PIEBALDconsult8-Jul-10 3:02
mvePIEBALDconsult8-Jul-10 3:02 
QuestionHow to Draw Image In Ellipse. Pin
Anubhava Dimri7-Jul-10 20:06
Anubhava Dimri7-Jul-10 20:06 
AnswerRe: How to Draw Image In Ellipse. Pin
Abhinav S7-Jul-10 20:12
Abhinav S7-Jul-10 20:12 
GeneralRe: How to Draw Image In Ellipse. Pin
Anubhava Dimri7-Jul-10 20:49
Anubhava Dimri7-Jul-10 20:49 
QuestionClarification Pin
Joe Rozario7-Jul-10 19:10
Joe Rozario7-Jul-10 19:10 
AnswerRe: Clarification Pin
Eddy Vluggen8-Jul-10 3:04
professionalEddy Vluggen8-Jul-10 3:04 
QuestionThreads in Windows Service Pin
ayandelhi7-Jul-10 18:36
ayandelhi7-Jul-10 18:36 
AnswerRe: Threads in Windows Service Pin
Richard Andrew x647-Jul-10 18:46
professionalRichard Andrew x647-Jul-10 18:46 
AnswerRe: Threads in Windows Service Pin
geo_m8-Jul-10 1:27
geo_m8-Jul-10 1:27 
JokeRe: Threads in Windows Service Pin
Pete O'Hanlon8-Jul-10 2:39
mvePete O'Hanlon8-Jul-10 2:39 
JokeRe: Threads in Windows Service Pin
geo_m8-Jul-10 4:21
geo_m8-Jul-10 4:21 
AnswerRe: Threads in Windows Service Pin
Dave Kreskowiak8-Jul-10 3:35
mveDave Kreskowiak8-Jul-10 3:35 
QuestionCCITT4 compression Pin
Ice_Freez057-Jul-10 15:24
Ice_Freez057-Jul-10 15:24 
AnswerRe: CCITT4 compression Pin
Roger Wright7-Jul-10 15:34
professionalRoger Wright7-Jul-10 15:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.