Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8974593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:42:51+00:00 2026-06-15T18:42:51+00:00

I have two string which should be put together into one string. First string

  • 0

I have two string which should be put together into one string. First string is a input value and second string is a pattern how the first string should look.
Here is the example –
Input string( var val ) – 9165678823
Patter string( var mask ) – (999)999-9999
Output string should look like( var startVal ) – (916)567-8823
I have tried working out and this is my code

            var val = $(control).data("loadMaskValue"); // Input Value
            var mask = $(control).attr("mask");         //Masking Pattern
            var startVal = "";
            var j = 0;

            for (var i = 0; i < mask.length; i++) {
                    var c = mask.charAt(j);
                    if (c == '9' || c == 'X' || c == 'A') {    //Checks the char is normal char 
                        startVal += val.charAt(j);
                    }
                    else {
                        startVal += c;                      //Inserts the special char to string like ( ) -
                        startVal += val.charAt(j);
                    }
                    j = startVal.length;
                }

The problem with this code is it misses one number in between. The result of this code is
startValue – (965)688-2.
PLease help me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:42:52+00:00Added an answer on June 15, 2026 at 6:42 pm

    Here’s a slightly simpler implementation:

    var input = '9165678823';
    var mask = '(999)999-9999';
    
    var output = '';
    var offset = 0;
    
    for (var i = 0; i < mask.length; i++) {
        var char = mask.charAt(i);
    
        if ('9XA'.indexOf(char) != -1) {
            output += input.charAt(i - offset);
        } else {
            output += mask.charAt(i);
            offset += 1;
        }
    }
    
    console.log(output);
    

    ​Make sure that input has been stripped of all whitespace at the beginning and end.

    Demo: http://jsfiddle.net/qWtjk/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to have a mapping which maps two string into one string.
I have two strings, one a key and one a value, which I would
I have two string variables which are both file paths. The code that worked
I have two tables which looks something like this Table Queue int ID; string
I have a bean of type string[] which has two or more values. I
I have two vc++ dll projects, which will generate two dlls. A vector<vector<string>> object
I have simple form like this which accepts only two values string action and
I have a class which has two HashSet<String> collections as private members. Other classes
I have to compare two strings for case insensitive equality which one is faster
I have a class with a template parameter which should decide which of two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.