I guess no one told you that you can use more than one character for variable names. You really should use more descriptive names.
The big switch statement is not good style. Do you see the pattern the numbers are forming? You can use that to replace the whole switch statement with just one line. Except the last case, that has to stay in an If statement.
case n: m[i]=row.substring(nl,l(n+1));
but i got some errors and switched it back ,
my new code bellow the one i just posted is : i pass the first test and i get at the second test MANHATTAN but the chars are separated with a coma , could some one help on how to remove the coma between the chars âŚ(i use JavaScript)
That looks very good. Except that you canât use case n:. In that place you canât use an expression like n. It has to be a value like 17, 'c', or "jhsdfsf". So you have to use an If statement instead of a switch statement. Try the following:
if (0<=n && n<=25)
m[i]=...
else
m[i]=...
And for pasting code in the forum you should use the preformatted text button in the editor.
I tried to replace the coma from my strings with this comand but it doesnât work , does anyone have any ideeas?(i use JavaScript , a - is my string) (a.replace(/,/g , " "));
Your statement a.replace(/,/g , " "); to remove the commas from the string is right. If that doesnât help the commas are from somewhere else. Or they are not in the string at all and only get printed to the output. Maybe you use a wrong index when you output the strings.
a.replace(",", "whatever you want") would only replace the first comma.
The replace() method searches a string for a specified value, or a regular expression, and returns a new string where the specified values are replaced.
Example
var str = âMr Blue has a blue house and a blue carâ;
var res = str.replace(/blue/g, âredâ);
it sayâs a.replace(",", âwhatever you wantâ) is not a function on other tipes of framework it works⌠i stored the need strings in an array
after that i sliced that array and pushed it into another array and when i read that array with for loop i get the text but i get it with comas after each string , i guess what i need to do print some how every string from the array âŚ
Iâm not sure I understand what you are trying to do. Try to think about it this way.
As input you get a string with the text (save it as a string). You also get a number of strings with the âartworkâ for the letters. The first string represents the first line of the letters and so on (save them as an array of strings).
Then you have to print out the text with the artwork, also line after line.
For each line.
Let *str* be an empty string.
For each letter in the text.
Take the corresponding substring from the array and append it to *str*
Print *str*.
You donât have to transform any arrays, you just have to lookup the result with an array access and the substring function. You already know how to calculate the indices for substring.
hello (world)
first of all i am using java to solve the game
i am putting all the ascii representation of the letters in a hashMap with the letters as keys and String arrays as values.
to print the answer i build a string for each line of the answer, from the corresponding line of the letters.
for some reason when i enter the strings to the arrays on the map they lose the space characters on their end
i can solve it for most cases by hardcoding an extra space when i insert it to the answer.
but i am looking for a way to get those spaces in without hardcoding solutions.
this is the code i am using to insert values to the map:
for (int i = 0; i < h; i++) // inserts values to ascii map
{
String rOW = in.nextLine();
for (char j='A';j<='Z';j++)
{
String letter = String.valueOf(j);
String arr[] = ascii.get(letter);
arr[i]=rOW.substring(0,l-1);
rOW=rOW.substring(l);
}
ascii.get("question mark")[i]=rOW.substring(0,l-1);
}