Replicating characters to form a string

Hello,
I'm trying to write a method which creates a string consisting of n characters.
Something like:
replicate(Char, n);
where Char is a character and n is the number of times thischaracter is replicated in the string.
e.g.
replicate("U",10);
would produce;
"UUUUUUUUUU"
Any ideas?
John

public String replicate(char character, int
stringLength){
char[] chars = new char[stringLength];
Arrays.fill(chars, character);
return new String(chars);
}I think because he's new to java, I would start him up with a loop so he doesn't get too confused...

Similar Messages

  • How to find number of characters in a character string

    Hi,
      Can anyone please tell me about how to find the number of characters in a character string type variable.
    Reagards,
    Siva

    hi,
    Use STRLEN for Calculating String Length..
    Assign it to integer variable for Further Use.Suppse u need to find string length for "hai".. this piece of code will help u
    data:  var type string value 'hai',
             len type i.
    len = strlen(var).
    write len.

  • I need to pass a query in form of string to DBMS_XMLQUERY.GETXML package...the parameters to the query are date and varchar ..please help me..

    I need to pass a query in form of string to DBMS_XMLQUERY.GETXML package...the parameters to the query are date and varchar ..please help me build the string .Below is the query and the out put. ( the string is building fine except the parameters are with out quotes)
    here is the procedure
    create or replace
    procedure temp(
        P_MTR_ID VARCHAR2,
        P_FROM_DATE    IN DATE ,
        P_THROUGH_DATE IN DATE ) AS
        L_XML CLOB;
        l_query VARCHAR2(2000);
    BEGIN
    l_query:=  'SELECT
        a.s_datetime DATETIME,
        a.downdate Ending_date,
        a.downtime Ending_time,
        TO_CHAR(ROUND(a.downusage,3),''9999999.000'') kWh_Usage,
        TO_CHAR(ROUND(a.downcost,2),''$9,999,999.00'') kWh_cost,
        TO_CHAR(ROUND(B.DOWNUSAGE,3),''9999999.000'') KVARH
      FROM
        (SELECT s_datetime + .000011574 s_datetime,
          TO_CHAR(S_DATETIME ,''mm/dd/yyyy'') DOWNDATE,
          DECODE(TO_CHAR(s_datetime+.000011574 ,''hh24:'
          ||'mi''), ''00:'
          ||'00'',''24:'
          ||'00'', TO_CHAR(s_datetime+.000011574,''hh24:'
          ||'mi'')) downtime,
          s_usage downusage,
          s_cost downcost
        FROM summary_qtrhour
        WHERE s_mtrid = '
        ||P_MTR_ID||
       ' AND s_mtrch   = ''1''
        AND s_datetime BETWEEN TO_DATE('
        ||P_FROM_DATE||
        ',''DD-MON-YY'') AND (TO_DATE('
        ||P_THROUGH_DATE||
        ',''DD-MON-YY'') + 1)
        ) a,
        (SELECT s_datetime + .000011574 s_datetime,
          s_usage downusage
        FROM summary_qtrhour
        WHERE s_mtrid = '
        ||P_MTR_ID||
        ' AND s_mtrch   = ''2''
        AND s_datetime BETWEEN TO_DATE('
        ||P_FROM_DATE||
        ',''DD-MON-YY'') AND (TO_DATE('
        ||P_THROUGH_DATE||
        ','' DD-MON-YY'') + 1)
        ) B
      where a.S_DATETIME = B.S_DATETIME(+)';
    SELECT DBMS_XMLQUERY.GETXML('L_QUERY') INTO L_XML   FROM DUAL;
    INSERT INTO NK VALUES (L_XML);
    DBMS_OUTPUT.PUT_LINE('L_QUERY IS :'||L_QUERY);
    END;
    OUTPUT parameters are in bold (the issue is they are coming without single quotes otherwise th equery is fine
    L_QUERY IS :SELECT
        a.s_datetime DATETIME,
        a.downdate Ending_date,
        a.downtime Ending_time,
        TO_CHAR(ROUND(a.downusage,3),'9999999.000') kWh_Usage,
        TO_CHAR(ROUND(a.downcost,2),'$9,999,999.00') kWh_cost,
        TO_CHAR(ROUND(B.DOWNUSAGE,3),'9999999.000') KVARH
      FROM
        (SELECT s_datetime + .000011574 s_datetime,
          TO_CHAR(S_DATETIME ,'mm/dd/yyyy') DOWNDATE,
          DECODE(TO_CHAR(s_datetime+.000011574 ,'hh24:mi'), '00:00','24:00', TO_CHAR(s_datetime+.000011574,'hh24:mi')) downtime,
          s_usage downusage,
          s_cost downcost
        FROM summary_qtrhour
        WHERE s_mtrid = N3165 AND s_mtrch   = '1'
        AND s_datetime BETWEEN TO_DATE(01-JAN-13,'DD-MON-YY') AND (TO_DATE(31-JAN-13,'DD-MON-YY') + 1)
        ) a,
        (SELECT s_datetime + .000011574 s_datetime,
          s_usage downusage
        FROM summary_qtrhour
        WHERE s_mtrid = N3165 AND s_mtrch   = '2'
        AND s_datetime BETWEEN TO_DATE(01-JAN-13,'DD-MON-YY') AND (TO_DATE(31-JAN-13,' DD-MON-YY') + 1)
        ) B
      where a.S_DATETIME = B.S_DATETIME(+)

    The correct way to handle this is to use bind variables.
    And use DBMS_XMLGEN instead of DBMS_XMLQUERY :
    create or replace procedure temp (
      p_mtr_id       in varchar2
    , p_from_date    in date
    , p_through_date in date
    is
      l_xml   CLOB;
      l_query VARCHAR2(2000);
      l_ctx   dbms_xmlgen.ctxHandle;
    begin
      l_query:=  'SELECT
        a.s_datetime DATETIME,
        a.downdate Ending_date,
        a.downtime Ending_time,
        TO_CHAR(ROUND(a.downusage,3),''9999999.000'') kWh_Usage,
        TO_CHAR(ROUND(a.downcost,2),''$9,999,999.00'') kWh_cost,
        TO_CHAR(ROUND(B.DOWNUSAGE,3),''9999999.000'') KVARH
      FROM
        (SELECT s_datetime + .000011574 s_datetime,
          TO_CHAR(S_DATETIME ,''mm/dd/yyyy'') DOWNDATE,
          DECODE(TO_CHAR(s_datetime+.000011574 ,''hh24:'
          ||'mi''), ''00:'
          ||'00'',''24:'
          ||'00'', TO_CHAR(s_datetime+.000011574,''hh24:'
          ||'mi'')) downtime,
          s_usage downusage,
          s_cost downcost
        FROM summary_qtrhour
        WHERE s_mtrid = :P_MTR_ID
        AND s_mtrch   = ''1''
        AND s_datetime BETWEEN TO_DATE(:P_FROM_DATE,''DD-MON-YY'')
                           AND (TO_DATE(:P_THROUGH_DATE,''DD-MON-YY'') + 1)
        ) a,
        (SELECT s_datetime + .000011574 s_datetime,
          s_usage downusage
        FROM summary_qtrhour
        WHERE s_mtrid = :P_MTR_ID
        AND s_mtrch   = ''2''
        AND s_datetime BETWEEN TO_DATE(:P_FROM_DATE,''DD-MON-YY'')
                           AND (TO_DATE(:P_THROUGH_DATE,'' DD-MON-YY'') + 1)
        ) B
      where a.S_DATETIME = B.S_DATETIME(+)';
      l_ctx := dbms_xmlgen.newContext(l_query);
      dbms_xmlgen.setBindValue(l_ctx, 'P_MTR_ID', p_mtr_id);
      dbms_xmlgen.setBindValue(l_ctx, 'P_FROM_DATE', to_char(p_from_date, 'DD-MON-YY'));
      dbms_xmlgen.setBindValue(l_ctx, 'P_THROUGH_DATE', to_char(p_through_date, 'DD-MON-YY'));
      l_xml := dbms_xmlgen.getXML(l_ctx);
      dbms_xmlgen.closeContext(l_ctx);
      insert into nk values (l_xml);
    end;

  • Chinese characters in Forms 6i

    Hi Gurus,
    What are the settings required to enter Chinese characters in Forms 6i runtime.
    I am able to type chinese in MS Word. but when i type in Chinese in Forms i get ???????.
    Any help would be appriciated.

    Dhiraj Madan wrote:
    I am able to type chinese in MS Word. but when i type in Chinese in Forms i get ???????.You are comparing apples with toasters here. Just because one Application is capable of displaying UTF-8 characters this doesn't mean another one is capable of displaying UTF-8 characters too.
    What characterset are you using on the client? And what database characterset are you using (as you probably would want to store them in the database too)? Are you using 6i in client/server mode or in web?
    cheers

  • How to Identify the Same Characters in 2 Different Strings

    Hi All,
    I am requiring a suggestion on how to identify the same characters in 2 different Strings, for example:
    String str1 = "hello";
    String str2 = "llheo";
    Both Strings contain the same characters, but in a different order, so what would be the best technique to verify t that both Strings indeed contain the same characters?
    I was personally thinking along the lines of using the class, java.util.regex.Pattern?
    Any thoughts would me much appreciated. Thanks

    I would instead sort the characters, and then compare
    the sorted data.
    I'm fealing generous
        private static boolean anagram(String left, String right)
            if (left.length() != right.length())
                return false;
            char[] leftChars = left.toCharArray();
            char[] rightChars = right.toCharArray();
            Arrays.sort(leftChars);
            Arrays.sort(rightChars);
            return Arrays.equals(leftChars, rightChars);
        }

  • Passing values to form bean string array from dynamic added textboxes

    Hi,
    I am unable to pass values to form bean string array from a jsp in which I have incorporated dynamically adding of textboxes in javascript.
    I have given add/delete row option in the jsp. If there is single row, this is working fine. But after adding a row, I am not able to either do any validations on added textboxes or pass the values to the String array form bean variable.
    code snippet:
    var cell6 = row.insertCell(4);
    var element5 = document.createElement("input");
    element5.type = "text";
    element5.className = "formtext1";
    element5.size = "5";
    element5.value = "00.00";
    element5.name= "qty"; // this is a string array of the form bean.
    element5.onchange=function() {checkNumeric(this);};
    cell6.appendChild(element5);
    <html:text styleClass="formtext1" property="qty" value="" size="5" styleId="qty" onchange="checkNumeric(this)"/></td>
    form bean declaration
    private String[] qty; Please help.
    Edited by: j2eefresher on Jan 12, 2010 11:23 PM

    Shivanand,
    There's no need to post that much code when you could create a very short test case that demonstrates only the problem you are having.
    You're using &NAME. notation on something that isn't a page or application item. You can't reference PL/SQL variables that way (or any other way) outside the PL/SQL scope. For your situation, you could create a page item named P55_DOCID and assign it a value in the PL/SQL process (:P55_DOCID := DOCID;), then reference &P55_DOCID. in HTML areas like the success message.
    Scott

  • How to find no of numeric characters in a given string ???

    How to find no of numeric characters in a given string ???
    Thanks,
    Kathir

    sabre150 wrote:
    Use String.replaceAll() to replace any characters that are not numeric and then take the length of the resultant String....and this might be useful: [http://www.regular-expressions.info/]
    ;-)

  • SPECIFYING THE NUMBER OF IDENTICAL CHARACTERS WHEN SEARCHING A STRING

    Hey everyone,
    The built-in function indexOf() searches for a character "." in the string "1.2.3." if the value == 1.
    It searches nothing if the value == 0 or 2 or any number greater than 2.
    var txt:String = "1.2.3.";
    var output:String = String(this);
    if (txt.indexOf(".") == 1)
    trace(output);     //[object MainTimeline]
    The must be a simple method for specifying the number of characters "." when searching the string "1.2.3.".
    For example if there is 2 characters "." in the string "1.2.", then run through a statement but if it does not contain 2 characters "." then do nothing.
    There is a built-in function called contains but it is mainly used in XML.
    indexOf() looks like unstable javascript codes, one of those framework that unixers hate.

    Why have an alternative when the built-in RegExp class does the job better than anything else?   Is it that you find them too hard to work with?  If you want a one line solution and prefer to use the older built-in methods you can do so by creating your own custom class to do what you want... searching a string character by character for the one you wish to isolate and counting them.
    In any case, you have a solution to counting the number of "." characters.
    "Many" people say what?  I doubt many people say anything like that at all.

  • The display width of characters in forms 10g

    Hi,
    I am facing problem in setting the display width of titles in the form dynamically.
    Please tell if there is any fixed display width of characters in the form(including the small letters and caps).
    And if not then Is there any way to determine it instead of hit and trial.
    Thanks in advance,
    Preeti

    Hello,
    You can get it with 2 lines of Java
       public static int getWidth (Font f, String s)
          Rectangle2D rect = f.getStringBounds(s,new FontRenderContext(new AffineTransform(),true,true));
          return (int)rect.getWidth();
        } With the following sample code:
    System.out.println("Width="+getWidth(new Font("Arial", Font.PLAIN,14),"Hello"));Francois

  • Do you handle illegal characters in form entry?

    Hi everyone
    I have an application with lot's of forms. The users are entering single and double quotes causing database errors. I would like to treat the single and double quote problem.
    My questions are
    1. How do you guys treat the single and double quote problem ?
    2. are there any other characters that will cause java to break between form submission and database insert
    Stephen

    Hi Everyone thanks for the response.
    I'm familiar with the preparedstatement solution -- however the problem is that sometimes i need to build dynamic insert statements. If i could insert nulls in the prepared statement i would be finished. so i tried that solution by liberticide i wasn't able to get it to work .
    I tried to test it in a jsp page
    I had the following errors:
    empty character literal
    probably occurred due to an error in /test/ReplaceQuotes.jsp line 13:
    case ''': strB.append("\'");
    empty character literal
    probably occurred due to an error in /test/ReplaceQuotes.jsp line 13:
    case ''': strB.append("\'");
    unclosed character literal
    probably occurred due to an error in /test/ReplaceQuotes.jsp line 13:
    case ''': strB.append("\'");
    : expected
    probably occurred due to an error in /test/ReplaceQuotes.jsp line 13:
    case ''': strB.append("\'");
    Here is all the Code Below
    <%@ page import "java.io.*, java.text.*, java.util.*" %>
    <%@ page errorpage="JuvErrorPage.jsp"%>
    <%! public String getBR(String mystring) {
    StringBuffer strB = new StringBuffer();
    int len = mystring.length();
    char ch;
    // start scan throught the string
    for(int i=0; i <len; i++ )
    ch = mystring.charAt(i);
    switch(ch) {
    case ''': strB.append("\'");
    case '"': strB.append("\"");
    default: strB.append(ch);
    return strB.toString();
    %>
    any ideas ? ?

  • HTML special characters in form input

    In my site I store form input in my database. Before I store
    the data, I parse out smart quotes, en dashes, and other extended
    special characters and convert them into HTHML quivalents such as
    &#8217;
    All is well and good until the user goes to edit their info.
    In my form these characters show up in my <input> tags as
    their long-winded HTML equivalents, such as &#8217; instead of
    a smart apostrophe.
    Is there any way to convert these back to the special
    characters from the HTML on the form input text fields so that
    users can edit them without being confused?
    Thanks.

    Hmmm, well I ran the MX 6.1 updater and installed the two hot
    fixes that had to do with null pointer exceptions and it still does
    not work.
    Here is the detailed error I'm getting, if it helps. Any more
    ideas? Thanks again for the help, I'm really stuck on this one...
    The system has attempted to use an undefined value, which
    usually indicates a programming error, either in your code or some
    system code.
    Null Pointers are another name for undefined values.
    The error occurred in C:\Inetpub\wwwroot\store\index.cfm:
    line 1
    1 : <cfquery name="getBooks" datasource="#dsn#">
    2 : SELECT *
    3 : FROM products
    Please try the following:
    * Check the ColdFusion documentation to verify that you are
    using the correct syntax.
    * Search the Knowledge Base to find a solution to your
    problem.
    Browser Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;
    rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7
    Remote Address 127.0.0.1
    Referrer
    Date/Time 09-Oct-07 02:20 PM
    Stack Trace
    at
    cfindex2ecfm1770128649.runPage(C:\Inetpub\wwwroot\store\index.cfm:1)
    java.lang.NullPointerException
    at coldfusion.sql.QueryTable.populate(QueryTable.java:260)
    at coldfusion.sql.QueryTable.populate(QueryTable.java:159)
    at coldfusion.sql.Executive.getRowSet(Executive.java:505)
    at coldfusion.sql.Executive.executeQuery(Executive.java:974)
    at coldfusion.sql.Executive.executeQuery(Executive.java:886)
    at coldfusion.sql.SqlImpl.execute(SqlImpl.java:236)
    at
    coldfusion.tagext.sql.QueryTag.doEndTag(QueryTag.java:447)
    at
    cfindex2ecfm1770128649.runPage(C:\Inetpub\wwwroot\store\index.cfm:1)
    at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:147)
    at
    coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:357)
    at
    coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:62)
    at
    coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:107)
    at coldfusion.filter.PathFilter.invoke(PathFilter.java:80)
    at
    coldfusion.filter.LicenseFilter.invoke(LicenseFilter.java:24)
    at
    coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:47)
    at
    coldfusion.filter.BrowserDebugFilter.invoke(BrowserDebugFilter.java:52)
    at
    coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:2 8)
    at
    coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:35)
    at
    coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:43)
    at
    coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
    at coldfusion.CfmServlet.service(CfmServlet.java:105)
    at
    jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:91)
    at
    jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
    at
    jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:249)
    at
    jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:527)
    at
    jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:192)
    at
    jrunx.scheduler.ThreadPool$DownstreamMetrics.invokeRunnable(ThreadPool.java:348)
    at
    jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:451)
    at
    jrunx.scheduler.ThreadPool$UpstreamMetrics.invokeRunnable(ThreadPool.java:294)
    at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)

  • How to make an XML in form of String to well-formed XML document

    Hi Folks,
         Thanks for all you support in Advance, i have a requirement, where i have an XML in one line string form and i wondering how to convert into well formed XML?
    Input XML sample:
    <root> <one><link1></link1></one><two></two> </root>
    to well-formed XML
    <root>
          <one>
              <link1></link1>
         </one>
         <two>
         </two>
    </root>
    I was trying to create a well-formed document using DOM or SAX parsers in ExcuteScript activity, but it is leading to some complicated exceptions. And i am looking for the simplest way for transformation.
    Please let me know
    thanks,
    Rajesh

    Rajesh,
    I don't understand. There is no difference between the two XML instances other than whitespace. They are both well-formed XML.
    <root> <one><link1></link1></one><two></two> </root>
    <root>
          <one>
              <link1></link1>
         </one>
         <two>
         </two>
    </root>
    Steve

  • Removing binary characters/ special chrs from string entered by user

    Dear gurus,
    I have a string entered by users in database from where i am pulling data into SAP BW.
    Th problem is that the string contains binary characters. It is showing error and cant be upoaded
    Is there any function module/ code that removes binary data an special chrs from string??
    Pls help. thanks.

    Hi,
    U can use the Tcode:  RSKC,
    to allow the special charecters...
    otherwise if u r sure that u r facing only that type of errors..then u can allow the
    errors in ERROR HANDLING tab present in the infopackage screen < Update tab
    bye,
    sunil4points

  • Special characters in a javascript string...

    Hey folks, in the javascript project I'm working on, there's a requirement that an SOH character (start of header, #1 in the ASCII character set) be included in a string. Does anybody know how that character can be inserted in a javascript string? Thanks in advance.

    Thanks to both of you for your good advice. One last question: the project that I'm working on involves exporting the contents of an Adobe InCopy CS2 document to a text file. Before the export occurs, I insert a line that starts with ACSII character 1 and ends with ASCII character 2 , at the top of the file. This tells a subsequent process how and where to push the file. The export is working as it should. However, the ACSII control characters are not exported with the text file. Any thoughts on how, or if, this possible?

  • Maximum number of characters for a BPEL string variable

    Hi,
    What is the maximum numbers of characters that a string variable in BPEL process can hold??.
    Is there any document which describes the datatypes in BPEL.
    Regards
    V Kumar

    Trick question - with or without the use of the FM GUI?
    1. Via the FM interface to define a variable, FM will only save the first 1022 characters of your variable definition - if you dare try to enter that many via the GUI dialogue slot.
    2. Importing a variable via MIF, adds virtually any length - I've tested out 2510 characters. HOWEVER, FM will only display the first 1023 characters of this string.
    If you save the file to MIF, you can still see the original length of the variable. The other caveat is that if you touch any of these long variables via the FM GUI (Edit Variables), then FM will truncate it down to 1022 characters - regardless of how you save (binary or MIF).
    FWIW - Klaus Daube lists (see: http://daube.ch/docu/fmaker25.html ):
    Until FM 7.2: up to 255 characters including meta-notations (such as <Default ¶ Font> or \t - this counts as 16 resp. 2 characters). See also note Variables below
    From FM 8.0: up to 2023 Windows Codepage characters or up to 2022 UTF-8 characters
    I'd say that this is not quite correct. You could enter more than 255 prior to FM 7.2 as well, but again the display issue via the GUI kicked in and truncated down to 255. The newer versions only display 1022/1023 but you can enter more than 2510 characters (which in this case is futile anyway).

Maybe you are looking for

  • Form 16 - Issue on arrear amount

    Dear all, I have run payroll of April, 2010 and also for May month with revision of salary w.e.f. April, 2010. There some employees are getting arrears. In form 16 when I am checking the amount of that wage type in emoluments paid (page no. 4) that i

  • Where is the software for the Lenovo G550???

    I want to do a clean install and replace the pre-installed Vista with Windows 7. I see that the Lenovo G550 download page has drivers for Windows 7, but where is the pre-installed software, like Veriface, camera software, and all other pre-installed

  • Why does my answer phone kick in on first call but then go through if it is phoned again iphone 5c

    why does my answer phone kick in on first call but then go through if it is phoned again iphone 5c

  • Automatically add to mobileme gallery

    If a smart folder is synced with mobileme gallery, does its contents change the same as if it were the smart folder itself. For example, if sync a smart folder containing >4* from a project then add more images and rate them >4*, will they automatica

  • Warp stabilizer counting much more frames than actually exists...

    Hello, everyone! I've just installed Premiere CC 2014 and I'm having problems with Warp Stabilizer... I'm trying to use it in clip with 25s and 24fps, but when I click "Analyze" it shows 1035764 frames! Also, it will take 2560 minutes to analyze it a