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 9043725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:47:53+00:00 2026-06-16T10:47:53+00:00

I have a string: str = ‘View:{ Name:View1, Image:{ BackgroundImage:Image.gif, Position: [0, 0], Width:

  • 0

I have a string:

 str =    'View:{
            Name:"View1",
            Image:{
                BackgroundImage:"Image.gif",
                Position: [0, 0],
                Width: 320,
                Height: 480
            },

            Button:{
                BackgroundImage:"Button.gif",
                Transition:"View2",
                Position: [49, 80],
                Width: 216,
                Height: 71
            },

            Button:{
                BackgroundImage:"Button2.gif",
                Position: [65, 217],
                Width: 188,
                Height: 134
            },'

That I use this regex to add ‘_#’ to elements that have ‘:{‘ at the end of them

var i = 0;
str = str.replace(/([^:]+):{/g, function(m, p1) { return p1 + "_" + (++i).toString() + ":{"; });

The ouput is

str =    'View_1:{
        Name:"View1",
        Image_2:{
            BackgroundImage:"Image.gif",
            Position: [0, 0],
            Width: 320,
            Height: 480
        },

        Button_3:{
            BackgroundImage:"Button.gif",
            Transition:"View2",
            Position: [49, 80],
            Width: 216,
            Height: 71
        },

        Button_4:{
            BackgroundImage:"Button2.gif",
            Position: [65, 217],
            Width: 188,
            Height: 134
        },'

Then I do a bunch of stuff with it and now I need to strip out the ‘#’ from it. How would I go about removing those ‘#’

Not cessary but another problem I am having is the the first regex is incrementing starting from 0 and giving each element the next incremented number. I am trying to make it so that each element increments on its type.
Like this:

str =    'View_1:{
        Name:"View1",
        Image_1:{
            BackgroundImage:"Image.gif",
            Position: [0, 0],
            Width: 320,
            Height: 480
        },

        Button_1:{
            BackgroundImage:"Button.gif",
            Transition:"View2",
            Position: [49, 80],
            Width: 216,
            Height: 71
        },

        Button_2:{
            BackgroundImage:"Button2.gif",
            Position: [65, 217],
            Width: 188,
            Height: 134
        },'

Any input on what im doing wrong here too?

  • 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-16T10:47:54+00:00Added an answer on June 16, 2026 at 10:47 am

    For the first question, just replace _\d+:{ with :{

    For the second, you need a separate counter for each type. Try this:

    var i = {};
    str = str.replace(/([^:]+):{/g, function(m, p1) {
        i[p1] = (i[p1] || 0)+1;
        return p1 + "_" + i[p1].toString() + ":{";
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this virtual method: const string& my_class::to_string() const { string str(this->name + string(
I have a string str = txtName.Text (txtName is name of textbox control) How
I have a string str[] where str[0]=My-Name; str[1]=is-drew; I want to get a new
I have a string like: string str = https://abce/MyTest; I want to check if
I have a string: String str = a + b - c * d
I have a string like the following: String str = 4*5; Now I have
Suppose I have a string char* str . I print it to the buffer
Supposed I have the following string: string str = <tag>text</tag>; And I would like
Suppose I have the following code: foreach(string str in someObj.GetMyStrings()) { // do some
I have e.g. string str ='Àpple'; string strNew=; char[] A = {'À','Á','Â','Ä'}; char[] a

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.