Modifying Strings Without Getting Strung Out
✕
  • Solutions
    • Legacy Application Modernization
    • Distributed Computing
    • Modern UI/UX
    • Data Visibility
    • Enterprise Application Integration
    • Development Environment Optimization
    • Cloud Migration
    • Security
    • High Availability and Resilience
  • Products
    • Language
    • Development Environment
    • .NET Integration
    • Streaming Integration Platform
    • Web Services Framework
    • Roadmap
  • Services and Support
    • Professional Services Group
    • Developer Support
    • Application Support
  • Learning
    • Events
    • Online Courses
    • White Papers
    • Case Studies
    • Learning Resources
    • Blog
    • Synergy-e-News
  • Company
    • Leadership
    • Careers
    • Contact
    • News
  • +1-916-635-7300
  • Get Support
  • Documentation
  • Resource Center
✕
            No results See all results
            Modifying Strings Without Getting Strung Out
            • Solutions
              • Legacy Application Modernization
              • Distributed Computing
              • Modern UI/UX
              • Data Visibility
              • Enterprise Application Integration
              • Development Environment Optimization
              • Cloud Migration
              • Security
              • High Availability and Resilience
            • Products
              • Language
              • Development Environment
              • .NET Integration
              • Streaming Integration Platform
              • Web Services Framework
              • Roadmap
            • Services and Support
              • Professional Services Group
              • Developer Support
              • Application Support
            • Learning
              • Events
              • Online Courses
              • White Papers
              • Case Studies
              • Learning Resources
              • Blog
              • Synergy-e-News
            • Company
              • Leadership
              • Careers
              • Contact
              • News
            • +1-916-635-7300
            • Get Support
            • Documentation
            • Resource Center
            ✕
                      No results See all results
                      Modifying Strings Without Getting Strung Out
                      • Solutions
                        • Legacy Application Modernization
                        • Distributed Computing
                        • Modern UI/UX
                        • Data Visibility
                        • Enterprise Application Integration
                        • Development Environment Optimization
                        • Cloud Migration
                        • Security
                        • High Availability and Resilience
                      • Products
                        • Language
                        • Development Environment
                        • .NET Integration
                        • Streaming Integration Platform
                        • Web Services Framework
                        • Roadmap
                      • Services and Support
                        • Professional Services Group
                        • Developer Support
                        • Application Support
                      • Learning
                        • Events
                        • Online Courses
                        • White Papers
                        • Case Studies
                        • Learning Resources
                        • Blog
                        • Synergy-e-News
                      • Company
                        • Leadership
                        • Careers
                        • Contact
                        • News
                      • Home
                      • Blog
                      • Tech Article
                      • Modifying Strings Without Getting Strung Out

                      Modifying Strings Without Getting Strung Out

                      Published by Galen Carpenter on March 27, 2020
                      Categories
                      • Tech Article
                      Tags
                      • Language

                      We added the StringBuilder class to traditional Synergy in version 11 to provide some of the more useful functionality of the .NET StringBuilder class. StringBuilder is a way to manipulate string objects. Since a string object cannot be modified without creating a new string object, the StringBuilder class provides a way to modify a string without the overhead of creating multiple string objects.

                      The StringBuilder object has two properties, Capacity and Length. The Capacity property is the current number of bytes available for StringBuilder’s contents. Capacity can be set to an initial value when the StringBuilder object is instantiated, and it will automatically increase when the contents exceed the current capacity. The internal allocated capacity will automatically increase in increments of 8192 when the capacity exceeds 8192 and the contents exceed the current capacity to limit memory reallocation. The Length property is the number of bytes currently in use.

                      Four constructors allow you to specify the initial contents and capacity:

                      StringBuilder()
                      StringBuilder(capacity)
                      StringBuilder(string)
                      StringBuilder(string, capacity)

                      If the capacity is not specified or is less than 16, the StringBuilder object will be created with a minimum capacity of 16 bytes. Specifying the capacity as the largest length that is expected prevents memory reallocation when the size expands.

                      The Append method appends the specified alpha or string to the contents in the StringBuilder object. The AppendLine method appends the specified alpha or string and the default line terminator(s) to the end of the contents in the StringBuilder object. On Unix, this is a line feed. On Windows and OpenVMS, it’s a carriage return and line feed.

                      Append(alpha)
                      Append(string)
                      AppendLine(alpha)
                      AppendLine(string)

                      The Insert method inserts the alpha or string at the specified index into the contents of the StringBuilder object. A count value can also be specified to insert multiple copies of the text.

                      Insert(index, alpha)
                      Insert(index, string)
                      Insert(index, alpha, count)
                      Insert(index, string, count)

                      The Remove method removes the specified number of characters starting at the specified index from the contents of the StringBuilder object.

                      Remove(index, length)

                      The Replace method replaces all occurrences of the old text with the new text. It allows the start index and length to be specified so that the replacements may be limited.

                      Replace(old_string, new_string)
                      Replace(old_alpha, new_alpha)
                      Replace(old_string, new_string, index, length)
                      Replace(old_alpha, new_alpha, index, length)

                      The Clear method removes all characters and sets the length to zero to reinitialize the StringBuilder object.

                      Clear()

                      The Equals method compares one StringBuilder object with another. If the contents and length are equal, a true value is returned.

                      Equal(StringBuilder_object)

                      The ToString method creates a string object of the contents of the StringBuilder object. ToString(index, length) allows a substring of the StringBuilder object to be specified for the created string object.

                      ToString()
                      ToString(index, length)

                      Note that XCALL S_BLD now allows the destination argument to be a StringBuilder object.

                      Here’s an example:

                      record
                          sb,          @system.text.StringBuilder
                          str1,       @string
                          str2,       @string
                      
                      proc
                          str1 = “one”
                          sb = new system.text.StringBuilder(str, 17)           ;resulting in “one”, length 3
                          sb.append(“ three”)                       ;resulting in “one three”, length 9
                          sb.insert(3, “ two”)                          ;resulting in “one two three”, length 13
                          sb.Insert(“ four”, 14, 3)                  ;resulting in “one two three four four four”, length 28
                          sb.replace(“four”, “five”, 19, 9)  ;resulting in “one two three four five five”, length 28
                          sb.remove(19, 5)                              ;resulting in “one two three four five”, length 23
                          sb.replace(“ “, “-“)                           ;resulting in “one-two-three-four-five”, length 23
                          str2 = sb.tostring(8, 5)                    ;resulting in “three”, length 5
                      

                      With these methods, manipulating string objects is easier and doesn’t cause extra overhead. The StringBuilder class is already available in .NET, so with the addition of this class to traditional Synergy, your code can be common to both.

                      Share
                      0

                      Leave a ReplyCancel reply

                      This site uses Akismet to reduce spam. Learn how your comment data is processed.

                      • A Day in the Life of Solutions Architect Dan Ellis
                      • Synergex Announces Leadership Transition as William Mooney Retires; Neithard Foley Appointed New President
                      • Meet the Visionaries
                      • New SDI Release, 2025.10.2527
                      • Celebrating the Career of Bill Hawkins
                      • Announcements
                      • Beta Testing
                      • Case Studies
                      • Code Exchange
                      • CodeGen
                      • CTO's Thoughts
                      • Development Tools
                      • DevPartner Conference
                      • Education
                      • Events
                      • Harmony Core
                      • Hiring
                      • Industry News
                      • Just for Fun
                      • Licensing
                      • News
                      • Open Source
                      • OpenVMS
                      • President's Thoughts
                      • Professional Services Group
                      • Release Notifications
                      • Security
                      • Software
                      • Software Development
                      • Success Stories
                      • Tech Article
                      • UI
                      • Uncategorized
                      • White Papers

                      STAY CONNECTED with Synergex

                      • Blog
                      • Facebook
                      • LinkedIn
                      • YouTube
                      SOLUTIONS
                      • Legacy Applications Modernization
                      • Modern UI/UX
                      • Data Visibility
                      • Enterprise Application Integration
                      • Development Environment Optimization
                      • Cloud Migration
                      • Security
                      • High Availability
                      PRODUCTS
                      • Language
                      • Development Environment
                      • Connectivity and Open-Source Tools
                      • Release Strategy
                      • Roadmap
                      SUPPORT
                      • Professional Services Group
                      • Developer Support
                      • Application Support
                      LEARNING
                      • Events
                      • Online Courses
                      • Learning Resources
                      • Blog
                      • Synergy-e-News
                      COMPANY
                      • Customers
                      • Leadership
                      • Careers
                      • Contact
                      Modifying Strings Without Getting Strung Out

                      Privacy  |  Security  |  Terms  |  © 2024 Synergex

                      CodeGen 5.5.2 Released
                      March 19, 2020
                      Who Invited the Dog? Tips for Business Meetings While Sheltering in Place
                      April 7, 2020
                      CodeGen 5.5.2 Released
                      March 19, 2020
                      Who Invited the Dog? Tips for Business Meetings While Sheltering in Place
                      April 7, 2020