Replace content of one string with another?

sn0wman

How could I replace the letters in a String such as "Hello", with the letters here?

String bubbled = "ⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏ";

I was initially just doing a replaceAll ("a","ⓐ"), but I feel like there has to be a more efficient way of doing this.

Jeff Ward

You could use the characters a and to determine the offset values for the alphabet. In combination with a StringBuilder it should be rather efficient. Of course you would likely have to be very strict about the input string being only alphabet characters.

This is the code for what I described above:

public class Bubbled {
    public static void main(String[] args) {
        char bubbledA = 'ⓐ';
        int lowerCaseOffset = bubbledA - 'a';
        int upperCaseOffset = bubbledA - 'A';

        String input = "Hello";
        StringBuilder bubbledOutput = new StringBuilder();
        for (Character c : input.toCharArray()) {
            if (Character.isUpperCase(c)) {
                bubbledOutput.append((char)(c + upperCaseOffset));
            } else {
                bubbledOutput.append((char)(c + lowerCaseOffset));
            }
        }

        System.out.println(bubbledOutput.toString());
    }
}

Output

ⓗⓔⓛⓛⓞ

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Replace QML file content by another one

From Dev

Javascript :Replace URL content string with another url

From Dev

Replace a substring with another string in dynamic content

From Dev

replace the content of one field based on the content in another field

From Java

Replace one substring for another string in shell script

From Dev

SQLite: replace part of a string with another one

From Dev

CakePHP virtual field: replace one string with another

From Dev

Easiest way to replace one or another string with a value

From Dev

Replace one string and create a column with another

From Dev

Excel: Replace occurences of one character with another in a String?

From Dev

Replace one div with another div using dynamically created content

From Dev

Merge content of one file into another file by replace a function

From Dev

How to replace a string from one file with a match in another one?

From Dev

How to replace a matching string in one file with matching string in another file?

From Dev

How to replace any string with a concatenation of another string and one field in MySQL

From Dev

Replace string between two words with the content of another text file

From Dev

Read file, replace string and create a new one with all content

From Dev

Replace one string with the content pulled from other file

From Dev

Replace NaN's in one column with string, based on value in another column

From Dev

How to replace one char by another using std::string in C++?

From Dev

how to replace string from one span to another in notepad++ with regex

From Dev

Extract string from one line to another line and replace

From Dev

Append/replace string from one file with information from another

From Dev

Replace every matching string by another one in every line beginning with a pattern

From Dev

How to replace string with values from one datafame to another dataframe

From Dev

In Shell how to Replace string from one form to another form

From Dev

Replace NaN's in one column with string, based on value in another column

From Dev

How to replace one char by another using std::string in C++?

From Dev

Extract string from one line to another line and replace

Related Related

  1. 1

    Replace QML file content by another one

  2. 2

    Javascript :Replace URL content string with another url

  3. 3

    Replace a substring with another string in dynamic content

  4. 4

    replace the content of one field based on the content in another field

  5. 5

    Replace one substring for another string in shell script

  6. 6

    SQLite: replace part of a string with another one

  7. 7

    CakePHP virtual field: replace one string with another

  8. 8

    Easiest way to replace one or another string with a value

  9. 9

    Replace one string and create a column with another

  10. 10

    Excel: Replace occurences of one character with another in a String?

  11. 11

    Replace one div with another div using dynamically created content

  12. 12

    Merge content of one file into another file by replace a function

  13. 13

    How to replace a string from one file with a match in another one?

  14. 14

    How to replace a matching string in one file with matching string in another file?

  15. 15

    How to replace any string with a concatenation of another string and one field in MySQL

  16. 16

    Replace string between two words with the content of another text file

  17. 17

    Read file, replace string and create a new one with all content

  18. 18

    Replace one string with the content pulled from other file

  19. 19

    Replace NaN's in one column with string, based on value in another column

  20. 20

    How to replace one char by another using std::string in C++?

  21. 21

    how to replace string from one span to another in notepad++ with regex

  22. 22

    Extract string from one line to another line and replace

  23. 23

    Append/replace string from one file with information from another

  24. 24

    Replace every matching string by another one in every line beginning with a pattern

  25. 25

    How to replace string with values from one datafame to another dataframe

  26. 26

    In Shell how to Replace string from one form to another form

  27. 27

    Replace NaN's in one column with string, based on value in another column

  28. 28

    How to replace one char by another using std::string in C++?

  29. 29

    Extract string from one line to another line and replace

HotTag

Archive