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

  • Home
  • SEARCH
  • 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 986049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:15:29+00:00 2026-05-16T05:15:29+00:00

I have project in development where string operations like Hi + variable + ,

  • 0

I have project in development where string operations like “Hi ” + variable + “, welcome to Project” are used at many places (given example is very minor one).

One of the requirement is to convert it to string.format style.

It is very long and tedious job, where I would not like to break earlier working code due to any human error might happen while converting it.

I would like to if any Macro or VS command which I can create to handle it. Just like we mark block of code and do Extract function in Re-factor options.

  • 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-05-16T05:15:29+00:00Added an answer on May 16, 2026 at 5:15 am

    I felt the code was a little long to post here, but I posted an answer at my blog:
    http://www.brianschmitt.com/2010/08/converting-concatenated-string-into.html

    — EDIT —
    Per comment here is the relevant Macro – not sure why you cannot access…

    Public Sub ConvertToStringFormat()
        DTE.UndoContext.Open("ConvertToStringFormat")
        Dim textSelection As TextSelection = DTE.ActiveDocument.Selection
        Dim output As String = "string.Format(""{0}"", {1})"
        Dim delimt As String = ", "
        Dim fmtdTostring As String = ".tostring("""
    
        Dim txtSelection As String() = System.Text.RegularExpressions.Regex.Split(textSelection.Text.Trim, "\+\s_[+\n\r\t]|&\s_[+\n\r\t]|\+|&")
        Dim hardStrings As String = String.Empty
        Dim valueStrings As String = String.Empty
        Dim counter As Int16 = 0
    
        For Each str As String In txtSelection
            Dim tmpString As String = str.Trim
            If tmpString.StartsWith("""") Then
                hardStrings &= tmpString.Substring(1, tmpString.Length - 2)
            Else
                Dim fmt As String = String.Empty
                Dim indxToString As Int32 = 0
    
                If tmpString.ToLower.Contains(fmtdTostring) Then
                    indxToString = tmpString.ToLower.IndexOf(fmtdTostring)
                    fmt = tmpString.Substring(indxToString + 11, tmpString.Length - tmpString.ToLower.IndexOf(""")", indxToString) - 1)
                End If
    
                If fmt <> String.Empty Then
                    hardStrings &= "{" & counter.ToString & ":" & fmt & "}"
                    valueStrings &= tmpString.Substring(0, indxToString) & delimt
                Else
                    hardStrings &= "{" & counter.ToString & "}"
                    valueStrings &= tmpString & delimt
                End If
    
                counter += 1
            End If
        Next
    
        If valueStrings <> String.Empty Then valueStrings = valueStrings.Substring(0, valueStrings.Length - delimt.Length)
    
        textSelection.Text = String.Format(output, hardStrings, valueStrings)
        DTE.UndoContext.Close()
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently, I have worked in a project were TDD (Test Driven Development) was used.
Short version: I have a Django project under development & testing (not yet into
Am using below third party API in my project development http://undesigned.org.za/2007/10/22/amazon-s3-php-class I have done
I currently have a recently started project in development with a 2010 target date
I have a project that includes a copy of phpMyAdmin. I do development locally
I am a noob of iOS development. Now I have a project that parses
I have created a set of default project templates and development framework libraries. I
Situation I have been working on a project lately where the UI development seems
I have followed this guide: http://maven.apache.org/guides/plugin/guide-java-plugin-development.html I have created a maven-plugin project hello-maven-plugin with
I am creating a small commercial web project running Apache/WSGI/Django/MySQL. I have a development

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.