+ 2

How to count characters in a string ?

suppose "abcdef" (exclude the quotations) is a string! so how can i find the number of characters of it ! (in this case the characters are 6) ! anyone?😀

28th Oct 2017, 12:03 PM
afrinish Rizvi
afrinish Rizvi - avatar
10 Answers
+ 7
language?
28th Oct 2017, 12:05 PM
jay
jay - avatar
+ 4
# Using Python.. You can convert the string into list so as to make each character countable.. And use the len() function to obtain the length of the string; now in a list form, (number of chars in the string) afterwards... i.e. string = "abcdef" list(string) print(len(string))
28th Oct 2017, 1:18 PM
Cyel
Cyel - avatar
+ 4
String str = "afrinish"; System.out.print(str.length());
28th Oct 2017, 1:27 PM
D_Stark
D_Stark - avatar
+ 3
i did 😐
28th Oct 2017, 12:09 PM
afrinish Rizvi
afrinish Rizvi - avatar
28th Oct 2017, 12:10 PM
Manual
Manual - avatar
28th Oct 2017, 12:15 PM
Manual
Manual - avatar
+ 2
Please put the language of your question in the tags.
28th Oct 2017, 12:08 PM
sneeze
sneeze - avatar
+ 1
java 😁
28th Oct 2017, 12:06 PM
afrinish Rizvi
afrinish Rizvi - avatar
+ 1
Let's use Python to help us. Python has an inbuilt sum function, to find the number of characters in a string or table. This would be (kind of) equivalent to C++/C#'s len function. alphabet = "abcdefg" sum(alphabet) || int num = alphabet.length(); You may want to revise on your language documentation - my knowledge has some inaccuracies... hope i helped. edit0 Well now I know I helped. Just remember that the length method can not be ran on non-string type objects, so... (excluding arrays - under differrent circumstances) intergers and floats; there's not much that it can't affect...
28th Oct 2017, 12:07 PM
ghostwalker13
ghostwalker13 - avatar
+ 1
i tried your method ghostwalker13...it worked! import java.util.*; public class Program { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String ar= sc.next(); int num=ar.length(); System.out.print(num); } }
28th Oct 2017, 12:15 PM
afrinish Rizvi
afrinish Rizvi - avatar