JavaScript DHTML/Dojo toolkit/StringBuilder

Материал из Web эксперт
Перейти к: навигация, поиск

Append to string builder

 
<html>
  <head>
    <script type="text/javascript">
      var djConfig = {
        baseScriptUri : "js/dojo/",
        parseOnLoad : true
      };
    </script>
    <script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
    <script>
      dojo.require("dojox.string.Builder");
      dojo.require("dojox.string.sprintf");
      function testIt() {
        var b = new dojox.string.Builder("Java");
        b.clear();
        alert(b);
        b.append("Hello, world!");
        alert(b);
      }
    </script>
  </head>
  <body onLoad="testIt();">
  </body>
</html>



Clear string builder

 
<html>
  <head>
    <script type="text/javascript">
      var djConfig = {
        baseScriptUri : "js/dojo/",
        parseOnLoad : true
      };
    </script>
    <script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
    <script>
      dojo.require("dojox.string.Builder");
      dojo.require("dojox.string.sprintf");
      function testIt() {
        var b = new dojox.string.Builder("Java");
        b.clear();
        alert(b);
        b.append("Hello, world!");
        alert(b);
      }
    </script>
  </head>
  <body onLoad="testIt();">
  </body>
</html>



Create StringBuilder

 
<html>
  <head>
    <script type="text/javascript">
      var djConfig = {
        baseScriptUri : "js/dojo/",
        parseOnLoad : true
      };
    </script>
    <script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
    <script>
      dojo.require("dojox.string.Builder");
      dojo.require("dojox.string.sprintf");
      function testIt() {
        var b = new dojox.string.Builder("Java");
        b.clear();
        alert(b);
        b.append("Hello, world!");
        alert(b);
      }
    </script>
  </head>
  <body onLoad="testIt();">
  </body>
</html>



Insert at index

 
<html>
  <head>
    <script type="text/javascript">
      var djConfig = {
        baseScriptUri : "js/dojo/",
        parseOnLoad : true
      };
    </script>
    <script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
    <script>
      dojo.require("dojox.string.Builder");
      dojo.require("dojox.string.sprintf");
      function testIt() {
        var b = new dojox.string.Builder("Java");
        alert(b);
        b.insert(2, "r ");
        alert(b);
      }
    </script>
  </head>
  <body onLoad="testIt();">
  </body>
</html>



Replace string in string buffer

 
<html>
  <head>
    <script type="text/javascript">
      var djConfig = {
        baseScriptUri : "js/dojo/",
        parseOnLoad : true
      };
    </script>
    <script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
    <script>
      dojo.require("dojox.string.Builder");
      dojo.require("dojox.string.sprintf");
      function testIt() {
        var b = new dojox.string.Builder("Java");
        alert(b);
        b.replace("Java", "JavaScript");
        alert(b);
      }
    </script>
  </head>
  <body onLoad="testIt();">
  </body>
</html>