Extract a part of String
Hi Experts!
I have a database table in which there is a field 'TEXT' of data type 'STRING'.
I need to pick up the value behind the field string.
Field string has entry in this format:-
<name1><Time-stamp1>## 'some comment' ## 'Some comment1' ##<name2><Time-stamp2>##'Some comment3'##
##-signifies the beginning of a new line.
Now the problem is I need to pick only those values which are the latest, i.e 'some comment' & 'Some comment1'.
or you can say the comment corresponding to the latest time stamp.
Please suggest a way out.
Help will be appreciated.
Thanks in advance
Regards
Sourabh
Hi
Try this code:
DATA: MY_STRING TYPE STRING.
DATA: BEGIN OF T_COMMENT OCCURS 0,
LINE(1000),
END OF T_COMMENT.
DATA: LEN TYPE I.
TEXT-001 is <name1><Time-stamp1>## 'some comment'
## 'Some comment1' ##<name2><Time-stamp2>##'Some
comment3'##
MOVE TEXT-001 TO MY_STRING.
SPLIT MY_STRING AT '##' INTO TABLE T_COMMENT.
LOOP AT T_COMMENT.
CONDENSE T_COMMENT.
Check if the first character is '
IF T_COMMENT-LINE(1) = ''''.
*...if yes the line is a comment, so write the comment
LEN = STRLEN( T_COMMENT-LINE ) - 2.
WRITE: / T_COMMENT-LINE+1(LEN).
ENDIF.
ENDLOOP.
Max
Similar Messages
-
Extracting second part of string
hi
i have a string like abcd~12341sdfs
I have to extract the string after ~ symbol
Please let me know how ot do itYour same question from last week Extracting a part of Strng.
-
I have a string like 'abcd1234'. I want to extract only the number part to another variable. I dont know the occurance of the number in the string
Please help mePlease read this thread:
Re: Splitting numbers and alphabets -
I have a desc field and I want to extract everything to the right of the hyphen. Since you can't use substr in CR how can I do it? Thanks so much in advance!
There are a few options:
1. Use Split to split on hyphens and then use the second element in the resulting array
2. Use inStr to find the location of the hyphen (inStr returns back the index of the desired character in the string being searched) and then use Mid to retrieve all text after that index
a programmer learning programming from perl is like a chemisty student learning the definition of "exothermic" with dynamite -
String function in Oracle 9i to find part of string having two positions
Hi,
We need to extract the part of string having start and end position.
Like
Suppose the string is "TYPE ref_cur_type IS REF CURSOR" and need to extract name of the ref cursor i.e ref_cur_type.The length of the output is not fixed. But not able to extract the exact string.
Thanks,What is the criteria for part of string? Do you give start character and end character position like 3,9 etc? Or its just that the word that comes between two spaces?
Cheers
Sarma. -
How Can I extract each part of a string ??
Dear Sir:
I have a string like following to connect to Oracle Database:
JDBC_URL= jdbc:oracle:thin:@localhost:1521:ABChere,
I have Variables like:
driverClass="";
Hostname = "";
port = "";
SID="";
etc
I try to extract each part from this JDBC_URL,
then assign them to following variable separately:
driverClass="jdbc:oracle:thin";
Hostname = "localhost";
port = "1521";
SID="ABC";
Can some guru help give some good example and show how to do it??
Thanks and have a nice weekends.try using a regular expression (regex).
here, i am going to try to freeball it:
// JDBC_URL= jdbc:oracle:thin:@localhost:1521:ABC
Pattern p = Pattern.compile("(JDBC_URL)(\\s*)(=)(\\s*)(.*?:.*?:.*?)(:)(@)(.*?)(:)(.*?)(:)(.*?)")
Matcher m = p.matcher(text)
if(m.matches()) or if(m.lookingAt()){
String driverclass = m.group(5);
String hostname = m.group(8);
...group(10);
...group(12);
}note that (\\s*) means "any amount of whitespace" and (.*?) means "any amount of any character (reluctantly)".
i used that because i dont know the constraints on those values. for only numbers you can use (\\d+) etc
[http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html|http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html]
also, i put everything into ( ) - which is called a capture group - but that was just to make it clearer. in your final regex you may get
rid of most of those. -
Extract a part from a txt file
Hi, I've a simple problem which unfortunately can not solve.
I have some txt's that I want only to extract a part o them. (The first 100 characters). Here is my code:
import java.io.*;
public class ReadSource {
public static void main(String[] arguments) {
try {
FileReader file = new FileReader("1.txt");
BufferedReader buff = new BufferedReader(file);
boolean eof = false;
while (!eof) {
String line = buff.readLine();
if (line == null)
eof = true;
else{
int start = line.indexOf("something");
int end = line.indexOf("something_else");
String str2 = line.substring(start, end);
System.out.println(str2);
buff.close();
} catch (IOException e) {
System.out.println("Error -- " + e.toString());
}and the error tha java displays is:
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1438)
at ReadSource.main(ReadSource.java:21)
Exception in thread "main"Tim I'm very sorry but is still don't work. It still display the same error.
Look at my code
import java.io.*;
public class ReadSource {
public static void main(String[] arguments) {
try {
BufferedReader reader = new BufferedReader(new FileReader("1.txt"));
BufferedWriter writer = new BufferedWriter(new StringWriter());
String line = null;
while ((line = reader.readLine()) != null) {
writer.write(line);
writer.newLine();
String content = writer.toString();
// Now you have the whole file content into the content String
int start = content.indexOf("smth");
int end = content.indexOf("smth2");
String str2 = content.substring(start,end);
System.out.println("start = "+start+", end = "+end);
System.out.println(str2);
reader.close();
}catch (IOException e) {
System.out.println("Error -- " + e.toString());
}It looks very logical, I don't know what happens
Thank you very much for your help.
Kostas -
How to extract local part from email address
Hello, dear Colleagues.
Please, help to extract local part from email address.
Input string: "From: [email protected]"
Need to get output string between "space" and "@": "C.Norris"
Thanks.Thanks you, mjolinor.
It works.
Could you show me please how to do the same with regular expression?
Using -replace:
$InputString = "From: [email protected]"
$InputString -replace 'From: (.+?)@.+','$1'
C.Norris
Using -match:
$InputString -match 'From: (.+?)@.+' > $null
$Matches[1]
C.Norris
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " " -
[email protected]; [email protected],
if I only want first part of string, I meant before ;
is that split is the only way to handle this case?using split is the easiest way.
use something like this
&test = "[email protected];[email protected]";
&array = Split(&test, ";");
for &i = 1 to &array.Len
&email = &array[&i];
/* Do some processing */
end-for;
if you do not want to use split try using the following
&string = "[email protected];[email protected];[email protected];";
While Find(";", &string) != 0
&pos = Find(";", &string);
&email = Substring(&string, 1, &pos - 1);
&string = Substring(&string, &pos + 1, Len(&string) - &pos);
End-While;
Really, there are a lot of different possibilities of achieving what you want ...
Edited by: Hakan Biroglu on Jul 10, 2012 4:15 PM -
How to use the image manipulation palette to extract a part of an image
How to use the image manipulation palette to extract a part of an image?I have a parent image from which i need to extract a certain sub part.can somebody pls help me on how to use this particular tool?
ThanksUse the above snippet. You might need to convert the Image Type you are using with picture functions. The above snippet will give you good idea on how to achieve what you intend to.
-FraggerFox!
Certified LabVIEW Architect, Certified TestStand Developer
"What you think today is what you live tomorrow" -
Extract the numbers in string using regex
Hi,
How to extract the numers in string using regex?.
Already i tried split up the string using [\\s]
For ex: "Uting Tatk and Window Panet 15"
it gives the ans 15.
if the string is
For ex: "Uting Tatk and Window Panet 15 New!"
i can't find the number.
so plz give me some idea to get the number frm String.
ThanksI am developing a java project to extract Table of
content in a particular
PDF.
i extracted all topics.
then i want 2 extract page number from dat extracted
TOC.
if the TOC ends with number then i can easily find
out the number
but in vain if the TOC ends with like this
"Uting Tatk and Window Panet 15 New!".
i could n't find the page number.What will you do if it says:
"15 ways to find topics 42 new" -
How to used REGEXP_REPLACE for replace part of string ?
hi
How can i replace part of string as following , i want to replace space in date by "-"
SELECT
REGEXP_REPLACE(upper('Daivd bought stuff by 2000 USD on 12 Sep 2012 from KL and left kl on 20 Sep 2012'),
'[0-9]{1,2}[^0-9](JAN|FEB|MAR|APR|JUN|JUL|AUG|SEP|OCT|NOV|DEC)[^0-9][0-9]{4}',
' ','-') "REGEXP_REPLACE"
FROM DUAL;
the output will be like this
Daivd bought stuff by 2000 USD on 12-Sep-2012 from KL and left kl on 20-Sep-2012
regardsI thought the questions is answered.
Your code will not work, because the alternate expression applies only to the four digit year and the month.
If you want to recognize both date formats with one expressions, you have to group the complete expressions.
The disadvantage of this would be, that the backreferences would not work in the same way because you would have more groups.
I advice to use two separate regular expressions for this task.
Take a look at the following example if you simply want to fill the gaps with -:
with yourtable as
select 'Daivd bought stuff by 2000 USD on 12 Sep 2012 from KL and left kl on 20 Sep 2012' text from dual union all
select 'Daivd bought stuff by 2000 USD on Sep, 20 2012 from KL and left kl on Sep, 20 2012' text from dual
SELECT
REGEXP_REPLACE(
REGEXP_REPLACE(text,
'([0-9]{1,2}) (JAN|FEB|MAR|APR|JUN|JUL|AUG|SEP|OCT|NOV|DEC) ([0-9]{4})','\1-\2-\3',1,0,'i'),
'(JAN|FEB|MAR|APR|JUN|JUL|AUG|SEP|OCT|NOV|DEC), ([0-9]{1,2}) ([0-9]{4})','\1-\2-\3',1,0,'i') regexp_replace
FROM yourtable;If you want same output-format for both date formats you could use this:
with yourtable as
select 'Daivd bought stuff by 2000 USD on 12 Sep 2012 from KL and left kl on 20 Sep 2012' text from dual union all
select 'Daivd bought stuff by 2000 USD on Sep, 20 2012 from KL and left kl on Sep, 20 2012' text from dual
SELECT
REGEXP_REPLACE(
REGEXP_REPLACE(text,
'([0-9]{1,2}) (JAN|FEB|MAR|APR|JUN|JUL|AUG|SEP|OCT|NOV|DEC) ([0-9]{4})','\1-\2-\3',1,0,'i'),
'(JAN|FEB|MAR|APR|JUN|JUL|AUG|SEP|OCT|NOV|DEC), ([0-9]{1,2}) ([0-9]{4})','\2-\1-\3',1,0,'i') regexp_replace
FROM yourtable;Edited by: hm on 25.09.2012 22:00 -
Hello,
I have a table like bellow
id group_name
1 TW Product Analyst PE
2 TW Tech Support Analyst SP
3 TW Tech Support Manager CE
4 TW Manager SP
5 Another Group Without End With 2 Characters
6 TW Product Coodinator MG
I would like to get just the last part of strings that ends with 2 characters(these 2 characters are states in Brazil).
The query answer need to seems like bellow
id group_name
1 PE
2 SP
3 CE
4 SP
6 MG
I appreciate any kind of help.
Thanksuser5495111 wrote:
Another way
with d as (
Select 1 id, 'TW Product Analyst PE' group_name from dual union all
Select 2, 'TW Tech Support Analyst SP' from dual union all
Select 3, 'TW Tech Support Manager CE' from dual union all
Select 4, 'TW Manager SP' from dual union all
Select 5, 'Another Group Without End With 2 Characters' from dual union all
Select 6, 'TW Product Coodinator MG' from dual
select id, substr(group_name, -2)
from d where id not in(select id from d where trim(substr(group_name,-3,1)) is not null)
This will not work if the fifth row id is null
with d as (
Select 1 id, 'TW Product Analyst PE' group_name from dual union all
Select 2, 'TW Tech Support Analyst SP' from dual union all
Select 3, 'TW Tech Support Manager CE' from dual union all
Select 4, 'TW Manager SP' from dual union all
Select null, 'Another Group Without End With 2 Characters' from dual union all
Select 6, 'TW Product Coodinator MG' from dual
select id, substr(group_name, -2)
from d where id not in(select id from d where trim(substr(group_name,-3,1)) is not null)
no rows selectedInstead or NOT IN use IN Clause
with d as (
Select 1 id, 'TW Product Analyst PE' group_name from dual union all
Select 2, 'TW Tech Support Analyst SP' from dual union all
Select 3, 'TW Tech Support Manager CE' from dual union all
Select 4, 'TW Manager SP' from dual union all
Select null, 'Another Group Without End With 2 Characters' from dual union all
Select 6, 'TW Product Coodinator MG' from dual
select id, substr(group_name, -2)
from d a where id in (
select id from d b where trim(substr(group_name,-3,1)) is null)
ID SU
1 PE
2 SP
3 CE
4 SP
6 MG
5 rows selected.SS -
I have a string of max length 40 characters. The string may contain 20 characters also with remaining 20 characters as 'SPACE'. Now from this string i want to fetch last four characters only
e.g. If my string contains " ABCDEFGH ", then from this i want to fetch only last 4 characters i.e. "EFGH" only.
How do i do it???Hi,
You can do this using the offset.
E.g
Var1 = 'abcdefgh'
then
Write: Var1+0(4).
this will extract the four characters from begining.
Regards,
DS -
How to extract a part of a string?
halo! please provide osme guidance:
�����������������������������������������������������������������
in a file, i have these parameters:
ip_ver=v4 ipadd=111.12.3.5 ip_msk=123.4.5.23 ...
�����������������������������������������������������������������
i want to extract the ip_ver and ip_msk parameters
i have divided the lines into tokens, and assign
String prop = token;
i encounter a problem in extracting ip_ver and ip_msk in the following
if (prop.startsWith ("ip_ver")== ture){
//...do something...
else if(prop.startsWith ("ip_msk") == true){
//..do somehting
there is nothing extracted out of "ip_msk"
thank you for your help.not sure if this is work but you could try to use the lastIndexOf(String str) method in the string class.
like:
String ip_ver=new String("v4 ipadd=111.12.3.5 ip_msk=123.4.5.23");
int startPoint = ip_ver.lastIndexOf("ip_msk");
// if ip_msk found then....
if(ip_msk != -1) {
String str_ip_msk = ip_ver.substring(startPoint); // get it
guess it'll depend if ip_ver is a string.
Maybe you are looking for
-
How to exclude Sales Orders from a planning run
Hi, I run MD02 and i discover that planned orders are being created as procurement proposals for sales orders and the planned independent requirement. I want planned order to be created only for the Planned independent requirements ONLY. Is there a w
-
Missing data when viewing older pdf in Adobe Reader XI
Hi. I have a large number of older PDFs which I can view fine in Adobe Reader 8 but when I view them with Adobe Reader 11 some of the lighter data is not visible. Is there some setting which would cause this? Do you have any other suggestions?
-
Is it possible to import .potx templates into Keynote?
I have a custom .potx template and want to import it to Keynote. Is this possible? Alternatively, is there a format that my industrial designer needs to use for the template in order for me to import it into Keynote?
-
Photostream does not have all images
Hi, I have several iOS devices and a MacBook Air. All of them show the same last 1,000 images in the photostream. My Windows 7 PC however shows only 160 of them. The latest images are missing. I use iCloud Control 3.1 and Windows 7 Professional 64bit
-
I need to give a user a new role so that they can just view the contents of a specific cube within RSA1. Say the cube is called ztest what entries do I need to enter in the following within PFCG so they can just see this cube Cross-application Autho