• <bdo id='tHnBo'></bdo><ul id='tHnBo'></ul>

    <tfoot id='tHnBo'></tfoot><legend id='tHnBo'><style id='tHnBo'><dir id='tHnBo'><q id='tHnBo'></q></dir></style></legend>

      <small id='tHnBo'></small><noframes id='tHnBo'>

        <i id='tHnBo'><tr id='tHnBo'><dt id='tHnBo'><q id='tHnBo'><span id='tHnBo'><b id='tHnBo'><form id='tHnBo'><ins id='tHnBo'></ins><ul id='tHnBo'></ul><sub id='tHnBo'></sub></form><legend id='tHnBo'></legend><bdo id='tHnBo'><pre id='tHnBo'><center id='tHnBo'></center></pre></bdo></b><th id='tHnBo'></th></span></q></dt></tr></i><div id='tHnBo'><tfoot id='tHnBo'></tfoot><dl id='tHnBo'><fieldset id='tHnBo'></fieldset></dl></div>

        将每 N 个字符的 char 放入一个 java 字符串中

        时间:2023-07-28
              <bdo id='ASHzx'></bdo><ul id='ASHzx'></ul>
                <tbody id='ASHzx'></tbody>

              <small id='ASHzx'></small><noframes id='ASHzx'>

              <i id='ASHzx'><tr id='ASHzx'><dt id='ASHzx'><q id='ASHzx'><span id='ASHzx'><b id='ASHzx'><form id='ASHzx'><ins id='ASHzx'></ins><ul id='ASHzx'></ul><sub id='ASHzx'></sub></form><legend id='ASHzx'></legend><bdo id='ASHzx'><pre id='ASHzx'><center id='ASHzx'></center></pre></bdo></b><th id='ASHzx'></th></span></q></dt></tr></i><div id='ASHzx'><tfoot id='ASHzx'></tfoot><dl id='ASHzx'><fieldset id='ASHzx'></fieldset></dl></div>

                  <tfoot id='ASHzx'></tfoot><legend id='ASHzx'><style id='ASHzx'><dir id='ASHzx'><q id='ASHzx'></q></dir></style></legend>
                  本文介绍了将每 N 个字符的 char 放入一个 java 字符串中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一个可变长度的 java 字符串.

                  I have a java string, which has a variable length.

                  我需要将 "<br>" 部分放入字符串中,例如每 10 个字符.

                  I need to put the piece "<br>" into the string, say each 10 characters.

                  例如这是我的字符串:

                  `this is my string which I need to modify...I love stackoverlow:)`
                  

                  我怎样才能得到这个字符串?:

                  How can I obtain this string?:

                  `this is my<br> string wh<br>ich I nee<br>d to modif<br>y...I love<br> stackover<br>flow:)`
                  

                  谢谢

                  推荐答案

                  类似:

                  public static String insertPeriodically(
                      String text, String insert, int period)
                  {
                      StringBuilder builder = new StringBuilder(
                           text.length() + insert.length() * (text.length()/period)+1);
                  
                      int index = 0;
                      String prefix = "";
                      while (index < text.length())
                      {
                          // Don't put the insert in the very first iteration.
                          // This is easier than appending it *after* each substring
                          builder.append(prefix);
                          prefix = insert;
                          builder.append(text.substring(index, 
                              Math.min(index + period, text.length())));
                          index += period;
                      }
                      return builder.toString();
                  }
                  

                  这篇关于将每 N 个字符的 char 放入一个 java 字符串中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何将char数组转换回字符串? 下一篇:Java中字符的大小不是2字节吗?

                  相关文章

                  最新文章

                    • <bdo id='EzoAb'></bdo><ul id='EzoAb'></ul>
                  1. <small id='EzoAb'></small><noframes id='EzoAb'>

                      <i id='EzoAb'><tr id='EzoAb'><dt id='EzoAb'><q id='EzoAb'><span id='EzoAb'><b id='EzoAb'><form id='EzoAb'><ins id='EzoAb'></ins><ul id='EzoAb'></ul><sub id='EzoAb'></sub></form><legend id='EzoAb'></legend><bdo id='EzoAb'><pre id='EzoAb'><center id='EzoAb'></center></pre></bdo></b><th id='EzoAb'></th></span></q></dt></tr></i><div id='EzoAb'><tfoot id='EzoAb'></tfoot><dl id='EzoAb'><fieldset id='EzoAb'></fieldset></dl></div>
                      <legend id='EzoAb'><style id='EzoAb'><dir id='EzoAb'><q id='EzoAb'></q></dir></style></legend>
                    1. <tfoot id='EzoAb'></tfoot>