Look at the 5th Char in a string

Hi,
In a string, after the 4th characters if it's a space i need to move the remaining characters in the string to another field.
For example,
String 1 = 'ABC DEF GH'.
The 5th Character is not a space and the 8th character is a space,thus GH will be assigned to another variable, say String 2 and keep the original string without GH in string 1. Thus we will have ,
String 1 = 'ABC DEF'
String 2 = 'GH'
Is there a way to do that ?
I need them urgently.
Thanks,
Loo

My code was for splitting string at space  (if offset is multiple of 4,like at 4 or 8 or 12 etc)..
find this code ,it will serve ur purpose -
data: str1 type string,
      str2 type string,
      D_CHAR.
data: len type i,
      count type i,
      off type i.
str1 = 'ABC DEF GH'.
count = 1.
len = strlen( str1 ).
do len times.
off = count - 1.
D_CHAR = str1+off(1) .
if count gt 4 and d_char = ''.
str2 = str1+count.
str1 = str1(off).
exit.
endif.
count = count + 1.
enddo.
write: 'STRING1 ',STR1,
      / 'STRING2 ',STR2.

Similar Messages

  • How to delete the last char in a String?

    i want to delete the last char in a String, but i don't want to convert the String to a StringBuffer or an array, who knows how to do?

    Try it in this way
    String MyString = "ABCDEF";
    MyString = MyString.substring(0,MyString.length()-1);

  • Deleting the last char of a string

    How can I Delete the last char of a string???
    example:
    asd@fdg@vvdfgfd@gdgdfgfd@gdfgdf@
    I want delete the last @!
    Tks in advance!

    hi,
    try this:
    lv_count = strlen(string).
    lv_count_last = lv-count - 1.
    replace string+lv_count_last(lv_count) in string by ' '.
    This should work.
    thnx,
    ags.
    Edited by: Agasti Kale on Jun 4, 2008 9:03 PM

  • Looking for the last item in a string set in a particular character style

    I should find each space that is the last character in a string set in a particular character style. For example, in the passage "123 456 789" (the underlined part here indicating a passage set in a particular character style), my ideal GREP search would yield a match after the digit 6.
    How do this?

    Excellent! This works perfectly. I have used your string with the bold character formatting, and replaced the matches with [nothing], set in None style.
    On second thought, I was surprised that it indeed had worked: why was the space replaced, and not deleted? Shouldn't I have used
    (?<!.)(\s)(?=\w)
    and replaced it with
    $2

  • How to  Remove the  Spc Char from a String ?

    Hi
    I am trying to stream out the file name after useing Timestamp. It throws some exception
    So I used the trim method for remove the space and spacial charater. But does't trim even space also.
    Please any body help me how to remove the space and spceial characters from my string.
    The file name ( String of value)
    2c5e773bad5e153cf91d7adabc121e62007-03-30 21:54:43.219.ivwr
    the file name after removing will be like this
    d2c5e773bad5e153cf91d7adabc121e620070330215443.ivwr
    pls help me
    Thanks,
    Merlin Roshina

    filename = filename.replaceAll("(?!\\.ivwr$)[- :.]","");

  • Detecting the first char inside string

    Hi,
    I search through all the String and char method but it doesn't seems to be any method to do this.
    Is there anyway I can detect the first char in a String
    Eg:
    @#@Hello!!
    Is there a method that allows me to detect H directly?

    I guess you mean the first character of a particular type - excluding '@' and '#'.
    morgalr wrote:
    There isn't a built in function like String.firstChar() that would give you the first character of any String. You can easily make one though.There is [String.charAt(int index)|http://java.sun.com/javase/6/docs/api/java/lang/String.html#charAt(int)] which returns the character at position index. This method can't read your mind though, so charAt(0) will return the very first character regardless of whether it is "good".
    In the Character class there is also a static method [isLetter(character)|http://java.sun.com/javase/6/docs/api/java/lang/Character.html#isLetter(int)] which reports "true" if the supplied character is a letter. There are lots of other methods in this class to report on the type of letter.
    Perhaps you could put these ideas together: write a loop to inspect each letter in turn until you come to one that is "good".

  • The last character of a string

    How to judge the last char of a string is " ?
    if (s.endsWith("""))or
    if (s.endsWith("/""))

    bet
    you just copied and pasted what the OP had written
    and quickly put that
    backslash in, hit post without previewing first just
    to make me look like
    a slow old sod! It's not fair ;-)
    kind regards,
    JosNope, I used the Alt-[numeric code] combinations to manually type each character. Cut-n-paste is for wimps, and actually typing single-stroke keys is for milquetoasts.
    Alt-[numeric code] is for real men ;-)

  • How can I select the last 2 chars of a string

    Hello all,
    I am trying to select the last 2 characters of a string to match them to another string. This is for a Poem generator that contains 20 or so words and I have to pick 2 words at random, them look at the last 2 characters to see if they match in each string. Say "Plain" and "Rain" would match because they both have "in" at the end. The length of each word could vary. I don't want this doing for me just what Method should I be looking at.
    Thanks.

    hi,
    try this:
    public class StringTest {
         public static void main(String args[]) {
              StringTest obj = new StringTest();
              obj.same();
         void same() {
              String rain = new String("Rain");
              String plain = new String("Plain");
              int rainLength = rain.length();
              int plainLength = plain.length();
              if(rain.substring(rainLength-2).equals(plain.substring(plainLength-2))) {
                   System.out.println("same");
              else {
                   System.out.println("different");
    }you can use the length method to get the length of a string and then use the substring method, passing it length-2, so get the last 2 chars.

  • How to invoke the char " in a string?

    Hi!
    I�m trying to invoke the char " in a string and I can�t think of any good way to do that.
    plz help.

    use
    String foo = new String("the string foo has the \"a string\" value");

  • Comparing char in a string to strings in a txt file

    Hi guys, i am dveloping a scrabble application for a project in jvava. Currently, i am trying to work on coding a computer player to play against a human, ive finished all the game logic nd 2 human players can successfully play on the same system.
    My problem is when coming up with the AI logic, i am faced with the problem of how to compare the computer player's letters to the dictionary txt file in order to find the possible words he can play.
    For example, the PC player has the letters A,B,E,G,T,F in his rack, it searches the dictionary and finds words that also contain these characters, so it would return words like AT, BAT, GATE, etc. I have already looke up the Jumble algorithm, but i dont really understand it(im still quite new to java).
    I already have a ditionary class which i put the code below.
    What i want to do now is just to come up with a simple method that takes a string, and compares the chars, and find words that match the char and return them but i dont knw hw to come about it.
    import java.util.Scanner;      
    import java.io.IOException;  
    import java.util.ArrayList;   
    import java.io.*;             
    public class Dictionary
        ArrayList<String> dictionary;
        public Dictionary() throws IOException
            dictionary = new ArrayList<String>();
        public void readInDictionaryWords() throws IOException
            File dictionaryFile = new File("c:/data/dict.txt");    // declare the file
            if( ! dictionaryFile.exists()) {
                System.out.println("*** Error *** \n" +
                                   "Your dictionary file has the wrong name or is " +
                                   "in the wrong directory.  \n" +
                                   "Aborting program...\n\n");
                System.exit( -1);    // Terminate the program
            Scanner inputFile = new Scanner( dictionaryFile);
            while( inputFile.hasNext()) {
                dictionary.add( inputFile.nextLine().toUpperCase() );
        public boolean wordExists( String wordToLookup)
            if( dictionary.contains( wordToLookup)) {
                return true;    // words was found in dictionary
            else {
                return false;   // word was not found in dictionary
        return"";
    }

    Loops...
    You take the first
    then second
    then third
    and etc
    You take the first 2
    the next 2
    the next 2
    etc
    all the way through n characters
    once you have gone through this, then you have to do all possible combinations of characters of 2 through n.
    Here is an implementation of N choose k for k up to 7:
    public class Junk {
      public Junk(){
      public void choose1(String s){
        int lCount=0;
        for(int i=0; i<s.length(); i++){
          System.out.println("("+s.charAt(i)+")");
          lCount++;
        System.out.println("Distinct Combinations: "+lCount);
      public void choose2(String s){
        int lCount=0;
        for(int i=0; i<s.length(); i++){
          for(int j=i+1; j<s.length(); j++){
              System.out.println("("+s.charAt(i)+", "+s.charAt(j)+")");
              lCount++;
        System.out.println("Distinct Combinations: "+lCount);
      public void choose3(String s){
        int lCount=0;
        for(int i=0; i<s.length(); i++){
          for(int j=i+1; j<s.length(); j++){
            for(int k=j+1; k<s.length(); k++){
              System.out.println("("+s.charAt(i)+", "+s.charAt(j)+", "+s.charAt(k)+")");
              lCount++;
        System.out.println("Distinct Combinations: "+lCount);
      public void choose4(String s){
        int lCount=0;
        for(int i=0; i<s.length(); i++){
          for(int j=i+1; j<s.length(); j++){
            for(int k=j+1; k<s.length(); k++){
              for(int l=k+1; l<s.length(); l++){
                System.out.println("("+s.charAt(i)+", "+s.charAt(j)+", "+s.charAt(k)+", "+s.charAt(l)+")");
                lCount++;
        System.out.println("Distinct Combinations: "+lCount);
      public void choose5(String s){
        int lCount=0;
        for(int i=0; i<s.length(); i++){
          for(int j=i+1; j<s.length(); j++){
            for(int k=j+1; k<s.length(); k++){
              for(int l=k+1; l<s.length(); l++){
                for(int m=l+1; m<s.length(); m++){
                  System.out.println("("+s.charAt(i)+", "+s.charAt(j)+", "+s.charAt(k)+", "+s.charAt(l)+", "+s.charAt(m)+")");
                  lCount++;
        System.out.println("Distinct Combinations: "+lCount);
      public void choose6(String s){
        int lCount=0;
        for(int i=0; i<s.length(); i++){
          for(int j=i+1; j<s.length(); j++){
            for(int k=j+1; k<s.length(); k++){
              for(int l=k+1; l<s.length(); l++){
                for(int m=l+1; m<s.length(); m++){
                  for(int n=m+1;n<s.length(); n++){
                    System.out.println("("+s.charAt(i)+", "+s.charAt(j)+", "+s.charAt(k)+", "+s.charAt(l)+", "+s.charAt(m)+", "+s.charAt(n)+")");
                    lCount++;
        System.out.println("Distinct Combinations: "+lCount);
      public void choose7(String s){
        int lCount=0;
        for(int i=0; i<s.length(); i++){
          for(int j=i+1; j<s.length(); j++){
            for(int k=j+1; k<s.length(); k++){
              for(int l=k+1; l<s.length(); l++){
                for(int m=l+1; m<s.length(); m++){
                  for(int n=m+1; n<s.length(); n++){
                    for(int o=n+1; o<s.length(); o++){
                      System.out.println("("+s.charAt(i)+", "+s.charAt(j)+", "+s.charAt(k)+", "+s.charAt(l)+", "+s.charAt(m)+", "+s.charAt(n)+", "+s.charAt(o)+")");
                      lCount++;
        System.out.println("Distinct Combinations: "+lCount);
      public static void main(String[] args) {
        Junk j = new Junk();
        j.choose7("1234567");
    }I'll leave it to you to integerate the algos into your app appropriately.

  • SQL Query To Select The 5th Element

    In the report I am currently working on, I am using an Add Command custom SQL query to pull the data that I need. The structure is a Call and a list of associated Activities. In this particular scenario, there are 8 activity notes for a type of call and I want to return the 5th one. The activity notes are a specific sequence of captured actions and I need the note from the 5th step in the sequence.
    This is what I have come up with:
    SELECT CALL.call_id,
         (select top 1 from (select top 5 CONVERT(char(8000),ACTIVITY.activity_note) from ACTIVITY
          where CALL.call_id = ACTIVITY.call_id
          order by ACTIVITY.creat_date desc))
         as activity_tx
    FROM CALL
    The intent of the Top 5 was to get the first 5 activity notes, of which the 5th note would be the last, then reverse sort them so I could take the Top 1 (which would be the 5th of 8). But I am getting a vague syntax error between "from" and "order by". Any suggestions would be appreciated.
    Thanks!
    Fuskie
    Who thought he had a solution but is flummoxed he can't bring it home...

    Hello,
    Let me explain that Crystal assumes the user knows how to write SQL. We only report on the data provided by the SQL you write.
    I did a quick search using Microsofts new search engine - www.bing.com and it returned this as well as lots more:
    http://forums.devshed.com/php-development-5/how-to-access-a-certain-element-in-the-results-of-606217.html
    Try searching in MSSQL's site also for more info on how to get the results you are looking for.
    Thank you
    Don

  • Compare the last Char to the First Char in a Sting

    Hello, this should be easy but I'm having problems so here goes.
    I get the user to input a Stirng and I want it to compare the last Char to the first Char. I have writen this but StartWith can take a Char?
    public static void main(String[] args) {
            // TODO code application logic here
            String strA = new String();
            int length = 0;
            char lastLetter;
            System.out.println("Please input your first String: ");
                   strA = EasyIn.getString();
                 length = strA.length()-1;
                   lastLetter = strA.charAt(length);
           if( strA.endsWith(lastLetter))
                System.out.println("The first letter matches the last");
           else
                       System.out.println("They Don't match");
    }I have tried lastLetter.endsWith(strA) but that dosn't work some thing to do with it not taking Char
    From reading you can go strA.startWith("R") and that would look for R but you can't put a char in that would be a single letter.
    I also tried to lastletter to a string but then charAt wouldn't work.

    fixed it I used substring as its a string object any one recomend a better way let me know
    public static void main(String[] args) {
            // TODO code application logic here
            String strA = new String();
            int length = 0;
            String lastLetter;
            System.out.println("Please input your first String: ");
                   strA = EasyIn.getString();
                 length = strA.length()-1;
                   lastLetter = strA.substring(length);
           if( strA.startsWith(lastLetter))
                System.out.println("The first letter matches the last");
           else
                       System.out.println("They Don't match");
    }

  • How to skip the '\n' char when reading with BufferedReader

    Hello to all the comunity that is at these forums, ;)
    I'm a venezuelan IT student, and as many arround here, I'm looking for some help with this homework...
    well the thing is that I need to read from the System.in untill I get the "" String. Well the initial idea was to make a BufferedReader object and put the br.readLine(); method inside a recursive method, like this:
       import java.io.*;
        public class P1_diccionary {
          String[] diccionario;
          int cont=0;
           void llenarDiccionario(String linea, String[] auxi)throws IOException{
             if(linea.compareTo("")!=0){
                 int aux = cont++;
                 diccionario = new String[cont];
                 for(int i=0;i<auxi.length;i++)
                     diccionario=auxi[i];
    diccionario[aux]=linea;
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    llenarDiccionario(reader.readLine(),diccionario);
    well, I think this one it's a nice idea, however, it doesn't work for me because the input is going to be just like this:
    word1: concept1...
    word2: concept2...
    word3: concept3...
    word4: concept4...
    and! it's going to be pasted on the console (that is "ctrl+c" then "ctrl+v")... that's the real problem that I have, the method that I did reads some lines not all of them, I think it's because there is no synchronization (guessing) between the ctrl+v and the execution of the program...
    so I thought about skiping the '\n' char, to do this I checked the readLine() method of the BufferedReader and found out that it calls a
    readLine(boolean ignoreLF)method and that ignoreLF and skipLF -boolean form the class- determine whether readLine() will skip the '\n' char or not:
    boolean omitLF = ignoreLF || skipLF;ok now the question: how do I make ignoreLF or skipLF = true? I tried to look more in the BufferedReader class but I didn't see how to change the skipLF value...
    well guess that's all, I'll really apriciate all of your help, and any other ideas that you might have to solve the problem...
    well thanks to everybody and see ya ;)

    Use read() instead of readLine(). This method will read characters, and does not treat the EOL charactger the same way. Just keep reading until you find a sequence of characters (two EOL sequences in a row) that matches your end condition. Just be careful, since different OSs have different EOL sequences ... \n, \n\r, or \r. Also, remember that you will have to deal with the EOL sequences. They will not be discarded automatically.
    You can also use read( char[], int, int) to read as many characters as you want, without regard to EOL sequences. This will only stop reading when EOF is reached, or when the next read will cause the underlying stream to block, or when you have read a specified number of characters. Again, this will not terminate at a EOL sequence, and will include the EOL sequences in your array.
    As far as readLine() is concerned, I think you want to stop when you have TWO successive reads that equal "".
    � {�                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Converting an array of char to a String object

    let's say i have an extremely long character array of 1 million chars and store a text file to it. is it safe to cast the character array into a String object? if not, what is a safe way to convert it to a String? I need to search through the String and create substrings and stuff. Thanks you!

    HOMEWORK ALERT HOMEWORK ALERT
    You can't cast from a character to a String. That doesn't work.
    However, in a fit of being helpful.
    Look at the constructors for the String object in the API
    Link ===> http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#String(char[])
    char[] charA = {'H', 'E', 'L', 'L', 'O', ' ', 'W', 'O', 'R', 'L', 'D' } ;
    String a = new String(charA) ;
    System.out.println(a) ;There's a price for my help, and it's this. Now that you understand what you can do, is it a good idea or a bad idea and why ???
    Explain.

  • Finding char in a string

    Hi,
    In C there is a function strchr() to find a char in a string. Is there an equivalent funtion in Java?
    The function indexOf() returns an int, but I want this char search would return a boolean value.
    So help please, thanks a lot
    chanh

    public boolean strchr(char myChar, String myString){
       for(int j = 0; j < myString.length(); j++){
          if(myChar == myString.charAt(j) return true;
       return false;
    }Is this what you are looking for?

Maybe you are looking for