Finding the charset of a string

Is it possible to determine the charset in wich a String was created? UTF-8, UTF-16, ISO 8859-1????

byte[] bytesEncodedInUTF8 = getSomeBytesFromSomewhere(); // you have some bytes encoded in UTF-8
String temp = new String(bytesEncodedInUTF8, "UTF-8"); // convert them to a string
byte[] bytesEncodedInISO88591 = temp.getBytes("ISO-8859-1"); // encode that string in ISO-8859-1

Similar Messages

  • Finding the key according to string length in java.util.Properties

    Finding the key according to string length in java.util.Properties.
    I know only String length only.

    i need to retrieve the values from the java.util.properties.
    we know that we need to give the key value in order to retrieve the datas.
    but my problem is i will give the length of the key instead of giving the key value but i need to retrieve the datas according to the length of the key.

  • How do i find the length of a string??

    trying to use the substring, I know the beginIndex (in my case 10), but the string will vary in size and so i need to find the last character and set it as the endIndex, how do i do this?
    public String substring(int beginIndex,
    int endIndex)Returns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring is endIndex-beginIndex.
    Examples:
    "hamburger".substring(4, 8) returns "urge"
    "smiles".substring(1, 5) returns "mile"
    Parameters:
    beginIndex - the beginning index, inclusive.
    endIndex - the ending index, exclusive.
    Returns:
    the specified substring.

    Hi
    To substring the string where u know the begin index and want to extract till the end use the following function from the String class of the java.lang package
    String substring(int beginindex);
    String test = "Hello";
    String xx = test.substring(1);
    The Value stored in xx will be ello
    This is in case u need till the end of the String
    If wanna skip the last character u can
    use
    String substring(int beginindex,int endindex);
    String test = "Hello";
    String xx = test.substring(1,test.length()-1);
    The Value stored in xx will be ell

  • Find the length of a string in pixels

    Hello all,
    Wondering if there's a way in PowerShell to find the length of a given string in pixels?

    That would depend on the font used to draw it, including size, bold / italic, etc.  Assuming you know those things, there's a TextRenderer.MeasureText method in the Windows Forms library:
    $string = 'This is my string. There are many like it, but this one is mine.'
    $font = New-Object System.Drawing.Font('Arial', 12, [System.Drawing.FontStyle]'Bold, Italic')
    $size = [System.Windows.Forms.TextRenderer]::MeasureText($string, $font)
    $size.Width

  • Find the path of a string using methods

    Dear Gurus ,
    I have the path "
    filestltrv\sap\mauals\text.xls' and i want using Methods in ABAP  to find the path '"
    filestltrv\sap\mauals\'.
    I suppose using loops and with finding '\' i will do it .
    Is any other Way ????
    Thanks a lot !!!!

    Hello,
    The FM: SO_SPLIT_FILE_AND_PATH is what you are looking for.
    BR,
    Suhas

  • Why in jndi tree I find the remote interface to String is so strange?

              when I view the jndi tree in weblogic server 61sp1
              I found such information:
              Bind Name: Enterprise1
              Class: class $Proxy94
              to String: ClusterableRemoteRef(10.132.0.161 [10.132.0.161])/275
              hash Code: 4568198
              Why the Class and to String like such? my license.bea
              is not a cluster version.
              

              Thanks you very much
              "Kumar Allamraju" <[email protected]> wrote:
              >EJB's are compiled with clustering options "ON". that's why you are seeing
              >a
              >ClusterableRemoteRef.
              >Don't worry, you will not be able to run WLS instances in cluster mode
              >without having a cluster license.
              >
              >--
              >--
              >Kumar
              >
              >"Eric nie" <[email protected]> wrote in message
              >news:3ca8238a$[email protected]..
              >>
              >> when I view the jndi tree in weblogic server 61sp1
              >> I found such information:
              >>
              >> Bind Name: Enterprise1
              >> Class: class $Proxy94
              >> to String: ClusterableRemoteRef(10.132.0.161 [10.132.0.161])/275
              >> hash Code: 4568198
              >>
              >> Why the Class and to String like such? my license.bea
              >> is not a cluster version.
              >>
              >
              >
              

  • Finding the length of a string

    hi im pretty new to all this,
    I am adding a part to my very basic program where the user can type "y" or "n" after they are being asked if they want to continue, I have been able to do this ok but im trying to make the program as air-tight as possible and i'm having troubble with the error checking.
    I have told the program what to do next based on the first character the user has typed (character 0), I would like my prorgam to prevent continuation if more than one character was entered into the string. At present it still recognises ydr (example) as a valid entry, is there anyway i can detect if there is more than one character in the sting? by doing so i'll be able to throw back an error to the user.
    do
      System.out.println("Would you like to continue (y/n)");
      System.out.println("");
      tmpans = scan.nextLine();
          if (tmpans.length > 1)
          //i know the above method of detecting the length dosn't work with strings, is there an alternative?
            exchar = true;
            System.out.println("You have entered too many characters");
          else
            exchar = false;
          while (exchar);
          if (tmpans.charAt(0) == 'y')
    ... etc

    String.getLength()Errr... String.length() ?Ya right. Whatever. lol
    It's still early in the day for me

  • Find the presence of a string in a schema

    i have a problem
    I want to create a procedure where i input the schema name.
    The procedure should check all the tables and attributes in that schema and check whether data is begining with "ABCD".
    If so it should give the table name and attribute name
    Please help me

    Actually the relevant post in that thread is Re: How to find out a tablename.
    As I Re: Scheme Search this request has come up a few times just recently. I still haven't got anybody to give me a sensible explanation as to why this functionality is required. It strikes me that this is probably a workaround for a horrendously bad data model or just a very undocumented system. If there is a real business need for such searches I would like to know what it is. Having said which ...
    As it happens I am working on an application at the moment that does have this requirement. This system is a (I thought) a very unusual one; that's why I'm interested to discover what business problems other people are solving.
    We don't use dynamic SQL driven off the data dictionary. That would be Teh Suck, performance-wise. So if this is a genuine business function (rather than a developer's hack) you probably need to start thinking outside the box on this one.
    Cheers, APC

  • Find the length of a String, without using any String API

    Hi All,
    I need to write an method which will accept String obj as an argument and will return its length, but method should not have any String API.
    Please help

    Simratpal wrote:
    Hi All,
    I need to write an method which will accept String obj as an argument and will return its length, but method should not have any String API.
    Please helpWell I have strongly argued against doing this, (it seems like a pointless exercise), and I have even stated that it cannot be done, even Reflection at some level will use a String method. I have not bothered to dissect wether the same is true with JNI. However, if we take the statement of the original problem exactly as stated, particularly the
    but method should not have any String API.i.e. we don't care if a String API is used 'under the covers', just so long as there is no direct usage in the new method that is written, then the answer is trivially easy:
    public class Main
        public static void main(String args[])
            Main worker = new Main();
            String str = "123456789";
            int len = worker.strLenUsingNoExplicitStringClassMethod(str);
            System.out.println("Length of string \""+str+"\""+" is "+len);
        public int strLenUsingNoExplicitStringClassMethod(String string)
            StringBuilder sb = new StringBuilder(string);
            return sb.length();
    }

  • How to find the occurrence of a word

    Hi...how can i write a method to find the occurrence of a string......
    i was thinkin of using an arraylist...but is there another way of doing it without an arraylist?
    thanks

    Do you mean the occurence of a string in a DOM tree, an XML document, some other file on disk or in another String.
    For the latter, it is pretty easy...int startAt = 0;
    int count = 0;
    while (startAt  != -1 ) {
      if ( (startAt = myString.indexOf(searchString, startAt)) != -1 ) count++;
    }

  • What is the use of search String?

    Hello there, I am trying to find the use of search string (DE01 and DE02). thanks.

    Hi,
    In your system DE01 and DE02 might be something configured for your client.
    Please check the below link to understand the logic of your search strings:-
    [http://help.sap.com/saphelp_erp2004/helpdata/en/43/0bd87b43de11d1896f0000e8322d00/frameset.htm]
    Regards,
    Gaurav

  • How to find the number of occurence of a string

    String str="The AR tech seeks experienced candidates in java,jsp. The candidates should have atleast 1 year of experience in the specified skills.";
    here i need to find the number of occurence of the string "experience".
    how to find it out?

    String str="The AR tech seeks experienced candidates in java,jsp. The candidates should have atleast 1 year of experience in the specified skills.";
    String findStr = "experience";
    int count = 0;
    int index = 0;
    while(index != -1) {
    index = str.indexOf(findStr, (count == 0 ? 0 : index + findStr.length()));
    if(index != -1) {
    count++;

  • How to find the number of occurance of a string in text field of Infopath form?

    Hi All,
    In Infopath text field, How to find the number of occurrence of a particular string in that field?
    Thanks in advance!

    You can check to see if it contains a string once by using the contains function, but there isn't a very clean way to do what you want. If you wanted to guess at the maximum number of occurrences, then you could:
    Box A has your initial. Set Box B to do a concat of string-before and string-after of Box A where it copies Box A minus the string we're looking for. Then we have Box C that does the same thing to Box B. Repeat as many times as you see necessary.
    Example:
    String: "1"
    Box A - "123451234512345"
    Box B - "23451234512345"
    Box C - "2345234512345"
    Box D - "234523452345"
    etc.
    We then have a field that has nested ifs looking backwards from Z -> A looking for a non-blank. Based on that, we return the number of occurrences. Again, this isn't clean, but it will work if you think there's a predefinable maximum.
    Andy Wessendorf SharePoint Developer II | Rackspace [email protected]

  • Find the number of consecutive numeric digits in string

    I am trying to see if a string has say 9 consecutive numeric digits in it but it will only work if the long string of numbers is the first string of numbers.
    e.g.
    This would recongnise the following string (if p_len = 9)
    Tel number 20 20 30 369 for 2nd meeting
         but would not recongnise the following
    For 2nd meeting tel 20 20 30 369
    Could anyone give guidance on how to proceed / a better way of find consecutive numbers in a string?
    Thanks
    Simon
    Code sample -
        LOOP AT TLINETAB.
    Remove blank spaces
          CONDENSE TLINETAB-TDLINE NO-GAPS.
    Find first number and its position *
          IF TLINETAB-TDLINE CA '0123456789'.
            pos = sy-fdpos.
    Does the next x characters contain only numbers?
            IF TLINETAB-TDLINE+pos(p_len) CO '0123456789'.
              append i_report.
            endif.
          ENDIF.
        ENDLOOP.

    Dear Simon,
    you want to check for consecutive numbers in a string. Then you may do the following -
    1. Get all the numbers in the given string into a table in a sequencial order, that is the order in which they appear in the string
    2. Once you have all the numbers you may find out if the numbers are consecutive or not. The following is the code which is not tested
    lv_len = 1.
    lv_pos = 1.
    lv_strlen = strlen ( lv_str ).
    do lv_strlen times.
      lv_alpha = lv_str+lv_pos(lv_len).
      if lv_alpha co '0123456789'.
       append lv_alpha to lt_number.
      endif.
      lv_pos = lv_pos + 1.
    enddo.
    loop at lt_number into ls_number.
      if lv_no is initial.
       lv_no = ls_number.
       lv_no = lv_no + 1.
      else.
       if ls_number eq lv_no and
          lv_consec is initial.
        lv_consec = c_x.
       else.
        clear lv_consec.
       endif.
      endif.
    endloop.
    if lv_consec eq c_x.
    *  !!! string has consecutive numbers
    endif.
    Hope it helps. Thank you.
    Regards,
    kartik

  • Here's how to find the right word in a string

    I needed to find the rightmost word in a string. I didn't find a simple formula in these forums, but I now have one, so I wanted to share it. Hope you find it useful.
    Assuming that the string is in cell A1, the following will return the rightmost word in the string:
    RIGHT(A1,LEN(A1)-FIND("*",SUBSTITUTE(A1," ","*",LEN(A1)-LEN(SUBSTITUTE(A1," ","")))))

    I found the problem. Whatever character was being used in the substitution was parsed out by the forum parser. I replaced it with "œ" (option q on my keyboard).
    =RIGHT(A1,LEN(A1)-FIND("œ",SUBSTITUTE(A1," ","œ",LEN(A1)-LEN(SUBSTITUTE(A1," ","")))))
    Still needs an error check for a single-word "sentence" and to remove the trailing period but it does seem to work. Pretty slick.
    Message was edited by: Badunit
    I see below that the problem was fixed by the OP.
    Message was edited by: Badunit

Maybe you are looking for