Questions tagged [charat]

The charAt() method is used to provide a single character by its index within a string.

The charAt() method is used to provide a single character by its index within a string.

261 questions
15
votes
8 answers

Possible problems with String reversing using charAt method

I saw a comment here that all solutions with charAt are wrong. I could not exactly understand and find something about charAt on internet. As I look the source code it just returns an element from the char array. So my question is that if there any…
user1474111
  • 856
  • 1
  • 12
  • 31
15
votes
2 answers

innerHtml prepend text instead of appending

I have a function that emulates typing with few lines of basic JavaScript code, however it appends text, but I want to prepend text to the element before any other already existing text/elements without changing html structure. How this can be…
vlad
  • 1,171
  • 3
  • 13
  • 26
9
votes
3 answers

traverse a string char by char javascript

function SimpleSymbols(str) { var letter =['a','b','c','d','e','f','g','h','i','j', 'k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']; var newstr = ""; for (var i = 0; i
Michael Sacks
  • 837
  • 1
  • 10
  • 17
7
votes
5 answers

Java String/Char charAt() Comparison

I have seen various comparisons that you can do with the charAt() method. However, I can't really understand a few of them. String str = "asdf"; str.charAt(0) == '-'; // What does it mean when it's equal to '-'? char c = '3'; if (c < '9') // How…
Kcits
  • 430
  • 1
  • 3
  • 12
7
votes
3 answers

How can I check if the char array has an empty cell so I can print 0 in it?

Code: public void placeO(int xpos, int ypos) { for(int i=0; i<3;i++) for(int j = 0;j<3;j++) { // The line below does not work. what can I use to replace this? if(position[i][j]==' ') { …
steven1816
  • 105
  • 1
  • 1
  • 5
5
votes
4 answers

Counting the number of specific occurrences in a java String

I am attempting to solve a problem where I create a method that counts the number of occurrences of capital and lowercase ("A" or "a") in a certain string. I have been working on this problem for a week now, and the main error that I am receiving is…
J. Doe
  • 146
  • 5
5
votes
3 answers

Java += operator on String with charAt() methods results in char addition

I'm working through the problems on Codingbat.com and bumped into the fact that for the += operator, a += b isn't necessarily exactly equal to a = a + b. This is well known and has been discussed on SO before, but I bumped into something strange…
jodles
  • 384
  • 1
  • 5
  • 15
5
votes
1 answer

Javascript charAt() breaking multibyte character string

This code breaks with nodejs v0.10.21 #!/usr/bin/env node "use strict"; var urlEncoded = 'http://zh.wikipedia.org/wiki/%F0%A8%A8%8F'; var urlDecoded = decodeURI( urlEncoded ); var urlLeafEncoded = urlEncoded.substr( 29 ); var urlLeafDecoded =…
4
votes
3 answers

How does the charAt() method work with taking numbers from strings and putting them into new strings in Java?

public String getIDdigits() { String idDigits = IDnum.charAt(0) + IDnum.charAt(IDnum.length() - 1) + ""; return idDigits; } In this simple method, where IDnum is a 13 digit string consisting of numbers and is a class…
4
votes
4 answers

Converting String (containing characters and integers) to integers and calculating the sum in JAVA

This method calculates the sum of all digits in a String of length 10. The String has to be of the form "12345?789x" or "12?4567890", where '?' can lie anywhere and has a value of 0, 'x' (if present) lies at the end of the String and is equal to…
ryan321
  • 63
  • 6
4
votes
1 answer

In PHP substring return �� these type of character?

I want to get the first character of a string in PHP. But it returns some unknown character like �. Why does that happen? $text = "अच्छी ाqस्थति में"; // Hindi String $char = $text[0]; // $text{0}; also try here . echo $char; // output like…
Gunjan Patel
  • 2,120
  • 3
  • 20
  • 40
4
votes
2 answers

if charAt equal to a list of characters

I want something like the following in Javascript if str.charAt(index) (is in the set of) {".", ",", "#", "$", ";", ":"} Yes, I know this must be simple, but I can't seem to get the syntax right. What I have now is theChar = str.charAt(i); if…
lbutlr
  • 326
  • 3
  • 15
3
votes
2 answers

Title Case JavaScript

I am trying to create a function in which after toLowerCase() input, will then capitalize the first letter in each element of an array. function title_case ( String ) { var result = ""; var text = String.toLowerCase().split(" "); for…
Kitty
  • 107
  • 1
  • 7
3
votes
1 answer

Use string methods to find and count vowels in a string?

When my code compiles it is giving me multiple outputs of my vowels. Almost like its giving me an output after it checks each character. how do i make it give just one output with all my vowels and others. in 1 output?? Please help... import…
Savage99
  • 59
  • 8
3
votes
3 answers

How to find text between less and greater than, then strip the <> in Java?

I don't know how to find these words.. example I have this text... The other day I went to the and bought some . Afterwards, I went to , but it was very so I left quickly and went to . I…
Storm Spirit
  • 1,326
  • 4
  • 16
  • 32
1
2 3
17 18