Two useful string functions - substr & substring

CK CK 3788 
Created at  
407 0 0

Now a days, javascript is widely used for web 2.0 programming.
In this case both function is very useful for string related algorithm.

You can simple get the required part of the string with high performance provided by client PC's performance.

1) substr() method extracts a specified number of characters in a string, from a start index.


Syntax: string.substr(start, length);

Quick Notes aout Substr:


If start is negative, Internet Explorer returns the whole string. That’s wrong! IE should use the last character in the string.



2) substring() method extracts the chars in a string between two specified indexes.


Syntax: string.substring(start, stop);


Quick Notes about Substring:


If start equals stop, it returns an empty string.
If stop is omitted, it extracts characters to the end of the string.
If either argument is less than 0 or is NaN, it is treated as if it were 0.
If either argument is greater than string’s length, either argument will use string’s length.
If start > stop, then substring will swap those 2 arguments.
Tags HTML Javascript RegExp Regular Expression Syntax Substring Facebook X
Comments 0
Similar posts
  1. Javascript based Regular Expression Tester
    374
  2. Javascript based Browser Sniffing
    433
  3. How to include Javascript from anonther ?
    410
  4. Is there URLEncode function in Javascript ?
    393
  5. IFRAME Auto Resize in IE, FireFox by Javascript
    455
  6. Move window
    548
  7. How to calculate page loading time ?
    359
  8. Number Of Vists
    511
  9. Add Message On Mouse Traling
    2,557
  10. Tooltip
    408
  11. Document Fader
    346
  12. Book Mark This Site
    405
  13. Icon Coupled Url
    427
  14. Button That Will Close The Browser Window
    350
  15. Button That Will Show The Page's Source
    387
  16. Add A Scrolling Status Bar Text To Your Site
    408
  17. Add This Page To Favorites
    400
  18. Code To Clear Browser History
    375
  19. Remove the spaces before begin and after end of text
    336
  20. How To Close A Pop-up Window ?
    443
  21. Pop Up Window On Top
    516
  22. How to display message on browser status bar ?
    476
  23. New Window
    604
  24. Color Table
    365
  25. Cursor Changer
    383
  26. Dual Scroller
    332
  27. Enlarge Image
    514
  28. Confirm The Link Clicked
    630
  29. Select And Deselect All Checkboxes By Javascript
    632
  30. Javascript Mouse Event Handler Example
    403
  1. To get web browser capability
    525
  2. Photo thumbnail viewer implemented in javascript
    487
  3. Javascript Confirmation
    593
  4. Javascript Prompts
    450
  5. How to know browser version in javascript ?
    444
  6. How to know the browser name in Javascript ?
    639
  7. Select All, None, Invert checkbox
    506
  8. Simple RSS Reader based on javascript
    502
  9. How to find the ip address of a client machine from a web application?
    518
  10. Put Date Time on HTML
    551
  11. IFRAME Auto Resize in IE, FireFox by Javascript
    455
  12. How to elimiate the "Restore Previous Session" dialog when FireFox 2.0 starts
    409
  13. How to include Javascript from anonther ?
    410
  14. Javascript based Browser Sniffing
    433
  15. Javascript based Regular Expression Tester
    374
  16. How to block a connection from the certain site ?
    352
  17. Is there URLEncode function in Javascript ?
    393
  18. Move window
    548
  19. How to calculate page loading time ?
    359
  20. Number Of Vists
    511
  21. Add Message On Mouse Traling
    2,557
  22. Tooltip
    408
  23. Document Fader
    346
  24. Book Mark This Site
    405
  25. Icon Coupled Url
    427
  26. Button That Will Close The Browser Window
    350
  27. Button That Will Show The Page's Source
    387
  28. Add A Scrolling Status Bar Text To Your Site
    408
  29. Add This Page To Favorites
    400
  30. Code To Clear Browser History
    375
Recently updated
  1. Why 100% SEO Guarantees Better User Engagement and How to Achieve It in Your Service
    40
  2. Why SPF and DKIM Are Essential for Linux Email Servers?
    34
  3. How do I create animated background for Google Meet?
    20,611
  4. MaxMind GeoLite2 vs. DB-IP Lite vs. ip-api.com: Choosing the Right Free IP Geolocation Solution
    244
  5. Meet Valkey: Why Redis Changed Its License, Why Valkey is Better, and How to Use It as a Drop-in Replacement
    94
  6. How Rogue Web Scrapers Are Stealing My Content and Destroying My Server
    157
  7. Array of arguments passed to script in PHP
    90
  8. Invalid Auction Storms in Ad Tech
    98
  9. Building MRC-Compliant Instrumentation in Ad Tech: Implementation Steps and Key Challenges
    202
  10. The Two Clocks of Ad Server Architecture
    70
  11. Frequency Cap Architecture Overview
    514
  12. Collecting Proof-of-Play from 100,000 Screens
    146
  13. Vector Search in Relational Databases (RDBs): Trends & Usage Environments
    287
  14. What is RedisVL?
    109
  15. Designing a Skill Registry Architecture: Minimize Token Usage and Maximize AI Performance
    230
  16. TPU & GPU Cluster Management Tools
    243
  17. The Concept of Scaffolding in AI Agents
    233
  18. Beyond Static Pipelines: Architecting LLM Multi-Agent Systems for Autonomous Workflow Orchestration
    583
  19. AI-DLC vs. AI-SDLC: Model-Centric vs. System-Centric AI Development
    258
  20. Fine-Tuning Open-Weight LLMs: Training, Licensing, and Deploying Custom Models with Ollama
    339
  21. Inside the Next-Generation Streaming Architecture: Ultra-Low Latency, SGAI, and AI Codecs
    202
  22. Machine Learning: Training vs. Ranking
    221
  23. The Continuous Learning Machine: Designing a Loop That Actually Turns
    222
  24. The Next-Gen Low-Latency Standards: LL-HLS & MoQ
    195
  25. Designing a Data Curation System Around a Vector Database
    220
  26. Extracting Context from Live Video: The Architecture Got Simpler When We Stopped Building Features
    256
  27. The New Ad Stack Behind Live Sports Streaming: Inside SGAI, EABN, and the Standards Race to Fix Live Monetization
    656
  28. Designing MLOps Architectures to Handle Seasonal Data Drift in EV Fleet Models
    195
  29. From 15 to 40+ FPS: Accelerating PyTorch Object Detection on Automotive ECUs
    217
  30. Understanding Data Lineage
    260