How do I cout each character in sentence

Discussion in 'Software' started by saarrajames, Oct 27, 2017.

  1. saarrajames

    saarrajames New Member

    5
    0
    1
    When I set in text object 'ok' system set to global variable 2

    when text display for example 'good' system set to global variable 4 ?
     
  2. dmarsh
    Honorary Member 500 Likes Award

    dmarsh Petabyte Poster

    4,305
    503
    259
    Avoid global variables, they kinda suck.

    What language are you coding in ?

    In javascript a naive implementation to count words would be something like this :-

    sentence.trim().split(/\s+/).length;

    Characters, well depends what you class as a character...

    It could simple be sentence.length, but I doubt it, as this counts spaces, non-printable characters etc.

    So the first thing you need to do is really define your problem in simple terms so yourself and others can understand it.

    If you decide that you want all non whitespace characters, then you can simply filter out the whitespace characters.

    javascript:alert('Hello World'.split('').filter(c => /\S/.test(c)));

    Try sticking that in your browser addressbar.
     
    Last edited: Oct 27, 2017

Share This Page

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.