1

Add the following character to each char in a string

 2 years ago
source link: https://www.codesd.com/item/add-the-following-character-to-each-char-in-a-string.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Add the following character to each char in a string

advertisements

i've to return it with the next character in the ASCII table, example:

string tmp = "hello";
string modified = "ifmmp";

I've tried to split string into characters and sum 1 to each character but it gives out an error.


Try this out:

public string NextCharString(string str)
{
    string result = "";
    foreach(var c in str)
    {
        if (c=='z') result += 'a';
        else if (c == 'Z') result += 'A';
        else result += (char)(((int)c) + 1)
    }
}

Edit: I assumed adding one to all characters is cyclic, that is, adding one to 'z' will give an 'a'

Tags string

Related Articles

How to get the first character of each word in a string?

I want this: var String1 = "Stack Over Flow" var desiredOutPut = "SOF" // the first Character of each word in a single String (after space) I know how to get the first character from a string but have no idea what to do this with this

Get the first character of each word in a string and its frequency

I have an array of Strings, for example: String[] words = {"apple", "peach", "apricot"}; How do I print out the first letters of each string with their corresponding frequency? For the example above, my expected output is: a

PHP - How to add the letter 'a' after each consonant of a string in a table?

I need to put an a after each consonant in an array so that for example: hello result will be : haelalaoProbably the easiest way to do it: preg_replace('/[b-df-hj-np-tv-z]/i', '${0}a', 'hello'); // => haelalao Demo

Replace the text as a value without knowing the following character

I am trying to replace text within one of my SQL columns. The text to replace can easily be found by finding all references of /*REPLACE*/ with the next character being a numeric value which must be jacked up by 5000. An example of the original value

Count the number of occurrences for each char in a string

I want to count the number of occurrences of each character in a given string using JavaScript. For example: var str = "I want to count the number of occurances of each char in this string"; Output should be: h = 4; e = 4; // and so on I tried s

Add the section title to each line using regex

I have a text file in the following format [Section1] property1 = value1 property2 = value2 [Section2] property1 = value1 property2 = value2 An example [Section foo] foo = 1 bar = "whatever" Is there any way I can add the section title to each l

Parentheses the third character of each word using sed

I'm trying to parenthesize the third character of every word in a text file using sed. I've tried manipulating: sed 's/\(\b[A-Z]\)/\(\1\)/g' filename This does what I need except, it parenthesizes the first character, not the third. It gives me: "Wel

Need to format the output of the string to a certain length, how can I count each char in a string to a defined limit

I need to limit the length of the output string without formatting the input string itself. I want to count each char of the string that is read up to an arbitrary limit - let's say 20 - at which point it will start printing on a new line. However, I

LINQ: Get the first character of each string in a table

Consider a string array shaped like this: string[] someName = new string[] { "First", "MiddleName", "LastName" }; The requirement is to get the first character from each element in the array. i.e. FML Previously have tried: s

The importance of the null character when initializing char tables

I'm new with C++ and I started to wonder, what happens if you leave the null character out when defining a char array? For example, if I define a char array with the null character: char myarray[] = {'a', 'b', 'c', '\0'}; and then I define it without

Get the first letter of each word in a string using regex

I'm trying to get the first letter of each word in a string using regex, here is what I have tried: public class Test { public static void main(String[] args) { String name = "First Middle Last"; for(String s : name.split("(?<=[\\S])[\\S

Add a & ldquo; + & rdquo; before each word in a string using jQuery

I have created an array, "outData", using javascript, which looks like this: I'm now trying to: loop through the outData array using jQuery each; if the checkbox called 'bmm' is ticked, split the strings in the outData array into individual word

How can I capitalize the first letter of each word in a string in Perl?

What is the easiest way to capitalize the first letter in each word of a string?See the faq. I don't believe ucfirst() satisfies the OP's question to capitalize the first letter of each word in a string without splitting the string and joining it lat

Get the first letter of each word in a string, in Javascript

How would you go around to collect the first letter of each word in a string, as in to receive an abbreviation? String: "Java Script Object Notation" Wanted result: "JSON" I think what you're looking for is the acronym of a supplied st

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK