logo
down
shadow

Removing all non letter characters from a string in C#


Removing all non letter characters from a string in C#

By : user2951222
Date : November 18 2020, 01:01 AM
I wish did fix the issue. A regular expression would be better as this is pretty inefficient, but to answer your question, the problem with your code is that you should use a different variable other than i inside your for loop. So, something like this:
code :
public static string RemoveBadChars(string word)
{
    char[] chars = new char[word.Length];
    int myindex=0;
    for (int i = 0; i < word.Length; i++)
    {
        char c = word[i];

        if ((int)c >= 65 && (int)c <= 90)
        {
            chars[myindex] = c;
            myindex++;
        }
        else if ((int)c >= 97 && (int)c <= 122)
        {
            chars[myindex] = c;
            myindex++;
        }
        else if ((int)c == 44)
        {
            chars[myindex] = c;
            myindex++;
        }
    }

    word = new string(chars);

    return word;
}


Share : facebook icon twitter icon
how to use regular expression for validation of String must begin with letter, all other characters can be letter/number

how to use regular expression for validation of String must begin with letter, all other characters can be letter/number


By : user2840854
Date : March 29 2020, 07:55 AM
Hope this helps I am doing validation of String which contains ASAHSHAS,342746726,GHG55656 this valid String and spaces are allowed. In advance!! , This should do it.
code :
^[a-zA-Z][a-zA-Z0-9 ]+$
A RegEx that validates a string starting with a lowercase letter, has no special characters, and has one Capital letter

A RegEx that validates a string starting with a lowercase letter, has no special characters, and has one Capital letter


By : sky wilb
Date : March 29 2020, 07:55 AM
this one helps. Basically, I need a Javascript RegEx that will ensure a string: , Something like this should work
code :
/^[a-z][a-z0-9]*[A-Z][a-z0-9]*$/
/^[a-z][a-z0-9]*[A-Z]?[a-z0-9]*$/
Replace each word in a string with (the first letter + number of characters between + last letter)

Replace each word in a string with (the first letter + number of characters between + last letter)


By : user4328314
Date : March 29 2020, 07:55 AM
it should still fix some issue I'm using objective-c to parse a sentence here: , Please try following code :
code :
NSString *myString = @"Some words to form a string";

NSArray *wordsInSentence = [myString componentsSeparatedByString:@" "];

NSMutableArray *expectedResultArray = [[NSMutableArray alloc] init];

for (NSString *word in wordsInSentence) {

    NSString *finalExpectedString = word;

    if (word.length > 2) {

        NSString *firstLetterInWord = [word substringToIndex:1];

        NSString *lastLetterInWord = [word substringFromIndex:[word length] - 1];

        finalExpectedString = [NSString stringWithFormat:@"%@%d%@", firstLetterInWord, (int)word.length - 2, lastLetterInWord];

    }

    [expectedResultArray addObject:finalExpectedString];

}

NSString *printString = [expectedResultArray componentsJoinedByString:@" "];

NSLog(@"Result : %@", printString);
Removing characters from column value and adding a new letter

Removing characters from column value and adding a new letter


By : Majikku Inki
Date : March 29 2020, 07:55 AM
To fix this issue I have the following data frame df1. I want to remove "/" from all values in column x2 and add letter v at the end of each value in x2. , You can use gsub to remove the / and paste0 to add the v in each row:
code :
df2 <- transform(df1, x2 = paste0(gsub("/", "", x2, fixed = TRUE), "v"))
df2
#  x1      x2
#1  1 aabbccv
#2  2 ffbbccv
#3  3 uubbccv
R: Removing all letter characters after a delimiter in a string

R: Removing all letter characters after a delimiter in a string


By : Brad Maggard
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I would like to remove all the letters ([a-z]) that come after a delimiter (e.g. "-"), in a string, e.g:
code :
gsub("(.*\\d).*", "\\1", s)
gsub("(.*\\-\\d*)[a-z]*", "\\1", s, ignore.case = TRUE)
Related Posts Related Posts :
  • How to use Addfields in MongoDB C# Aggregation Pipeline
  • MsTest TestCleanup method not called when an unhandled exception is thrown
  • missing last data when exporting gridview to excel
  • How to add array of objects to List in c#
  • Lambda Expression to order (sort) my list collection
  • Library for displaying music notation
  • How to compare two dictionaries in c# and get the output as True and False after validation
  • specify fields to be serialized with JSON
  • How do you obtain the content of a specific node using XmlDocument in C#?
  • How to ignore the first line in a csv file when you read the csv file in C#
  • c# - Problem calling public void from class
  • How to tell a class which objects it should create? Type vs. object confusion :(
  • Save CheckBox state to xml
  • WIX CAQuietExec NETSH Command Fails
  • Issues sending http put request every 60 seconds to RoR app
  • ConfigurationManager.ConnectionStrings.ConnectionString Issue
  • Real size WPF controls for printing
  • How to cancel properly?
  • C# String multiplication error
  • Using Solrnet and Assigning Attributes with Entity Framework Generated POCOs
  • Regex pattern for single backslash
  • TextBox: insert spaces for credit card number?
  • C# DLL loaded for exe-application is not found when launching similar DLL by rundll32.exe
  • Debug a Windows Service with WCF library
  • Open a file from an external assembly?
  • Servicestack RegistrationFeature Unable to bind request
  • Index was outside the bounds of the array confusion
  • Error in Xml to List code. The ':' character, hexadecimal value 0x3A, cannot be included in a name
  • I am trying to do a while loop with a string conditional statement in C#
  • C# 'Cannot access a disposed object. Object name: 'SslStream'.'
  • How to make Gecko use seperate CookieContainer per instance?
  • C# Advanced form "please wait"
  • Send and Receive data C# using network stream
  • How to discover that appsettings changed in C#?
  • Check what needs full trust
  • What is the execution order of an MVC Razor view/layout
  • Table designer (Entity Framework) is too resource intense
  • How to clean up an exception string so it can be displayed via Javascript Alert?
  • Configuring Amazon SES Feedback Notifications via Amazon SNS in ASP.NET MVC (C#)
  • C# api responce and request
  • Dynamodb putitem function not working properly
  • theme in windows phone(light or dark) using c#
  • Backup attached database file(.mdf) using c# and SQL Server
  • What is 'TextFile' and where it is uses in WPF project
  • Using same alias for multiple namespaces
  • how to move mails into separate folders
  • Multithreaded Uploader
  • Memory fragmentation?
  • C# correct exception handling
  • "Could not open macro storage" when accessing using file on another machine
  • How to access other directories of hosted server
  • C# Jagged Array check if value exists/true
  • Why can't I type Clone() properly?
  • exception on accessing dictionary from list
  • Getting the immediate response from server without waiting to 200 message
  • Why am I getting exception Directory Is Not empty?
  • Could not load file or assembly 'CefSharp.dll' or one of its dependencies
  • Sending Email By Using C# in unity3D?
  • Correct usage of await async in webapi
  • Program update code issue
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org