GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — javascript-2/strings/substrings.md at master · ufo-github/javascript-2

Expand file tree

/

substrings.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
28 lines (22 loc) · 778 Bytes
/

substrings.md

Copy path

File metadata and controls

28 lines (22 loc) · 778 Bytes
Raw
Copy raw file
Download raw file
Edit and raw actions

Substrings

substring is used to take a part of a string. Syntax: substring(first_index,last_index).

var a = 'Hello world!';
document.write(a.substring(1,6));

The preceding code snippet gives 'ello ' . Note that the 'w' (index 6) is not part of this substring.

We could also do,

var a = 'Hello world!';
document.write(a.substring(2));

This gives the whole string from the character with index 2. 'llo world!'

##substr

There is also a method substr() that works slightly differently. Instead of the second number being an index number, it gives the number of characters.

var a = 'Hello world!';
document.write(a.substr(1,6));

starts at the character with index 1 ('e') and then gives 6 characters, so the output is ello w

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.