Extract either string1 or string2 from another string
I have a string of data named "dump" with 500 or more bytes of data that will contain within it either (along with other data) the word "circle" or the word "square". (but not both)
I need to pull which ever one of these two words that is in the string "dump" and to create a string called "type" that contains only that word.
Is there an easy way to do this with a line of code or two?
thanks
if (FindPattern (dump, 0, -1, "circle", 0, 0) >= 0)
strcpy (typem "circle");
else if (FindPattern (dump, 0, -1, "square", 0, 0) >= 0)
strcpy (type, "square");
Proud to use LW/CVI from 3.1 on.
My contributions to the Developer Zone Community
If I have helped you, why not giving me a kudos?
Similar Messages
-
Extracting various bits of information from a string
Hi,
I am interested in extracting various pieces of information from strings (which were originally email bodies). For example email addresses (that are in the body of the email not the "from" field), phone numbers (which could have spaces between, international formats/conventions, ie not all numbers), profession (to match against a list I have), etc etc.
I am expecting that I would need to use Regex to find emails and phone numbers, and maybe tokenizing the string to match against my list of professions.
So I am more interested in some high level suggestions of how I should go about this.
In most cases, the source of the emails will be from 3 known sources. So in these case I will have a pretty good idea of the format/template that the response's will follow ( ie ".... name is XXXX XXXX ....." ) . This would then make extracting the useful information much easier. However, I need to allow for emails from unknown sources where nothing would be known about the format of the email.
Any help/suggestions/info would be appreciated.
The WhaleThanks.
Re: function object; You tip about the function object sounds like a very good idea. I have been thinking about the best way to do this and this sounds like a good way to do it.
Re: Regex - I have not used Regex much but I am assuming it wont be hard to find or create Regex expressions to find phone numbers and email addresses. Although as you say, names could be hard. Although in this case I will just have to rely on locations in known templates.
Thanks again,
:) -
Take and delete a String from another String
I have original input string= 111100001111
I need to Take for example the least 4 bits .... Output= 1111
and to be removed from the original input string so the original input string= 11110000
I am trying to make a generic one but the point is that I can not delete subset that I take from the original input String.
How can I take and delete from a string in the same time?
Solved!
Go to Solution.Something like this?
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Attachments:
Split String.png 13 KB -
Extracting string from another string
Hi,
I have a problem that I am having difficulty solving, if anyone has any bright ideas it would be a great help.
I have a description field in one of my tables and the description would read something like
my website can be found at www.mywebsite.com, and it is great
I want to be able to extract the web address from this sentance, so the result would be
www.mywebsite.com
I can do this specific for one sentance but I can't find a way to do it for many different sentances.
cheers in advancer u expecting this..?
select substr('my web site is www.abcd.com and u can...',instr('my web site is www.abcd.com and u can...','www.',1),instr(substr('my web site is www.abcd.com and u can...',instr('my web site is www.abcd.com and u can...','www.',1)),' ',1)) from dual; -
How can i extract using while the time from the string ?
First time how can i extract the time as string ?
And second how can i extract the time as DateTime.Now ?
public static void ExtractDateTime()
htmltoextract = new Uri("http://test.com");
client = new WebClient();
f = client.DownloadString(htmltoextract);
client.Dispose();
int index = 0;
while (index != -1)
int t = f.IndexOf(firstTag);
int g = f.IndexOf(lastTag);
a = f.Substring(t + firstTag.Length, g - t - 8);
The string look like this: thisisateststring201309202145andthenextimeinthestringis201309202130andthelastofthisexampletimeinthisstringis201309202115
What i need to do is first time to extract the time as string to a List<string> like this:
index 0 201309202145
index 1 201309202130
index 2 201309202115
The second time to extract the times as this time format: YYYYMMDDhhmm and also to add the times to a List.
First time and second time i mean first example and second example. To use my code but first time to extract it as strings second example as the format of YYYYMMDDhhmm
And i need to use the while and indexof and substring in this cases.Is the region always going to be "eu" or are you going to have more than one region. Since you are reading a string DateTime from different timezone than the computer you are reading the data you have to convert to a different timezone.
It looks like you have at least 'is' and 'eu' for regions. I don't know what offsets you need so try something like this.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Globalization;
using System.IO;
namespace ConsoleApplication1
class Program
static void Main(string[] args)
string input = File.ReadAllText(@"c:\temp\test.txt");
string pattern1 = @"imageUrls = \[[^\]]*\]";
Regex ex1 = new Regex(pattern1, RegexOptions.Singleline);
string pattern2 = @"region=(?'region'[^&]*)&time=(?'time'\d{12})";
Match match1 = ex1.Match(input);
Regex ex2 = new Regex(pattern2, RegexOptions.Singleline);
MatchCollection matches2 = ex2.Matches(match1.Value);
IFormatProvider provider = CultureInfo.InvariantCulture;
List<DateTime> dateTime = new List<DateTime>();
foreach (Match match2 in matches2)
string region = match2.Groups["region"].Value;
DateTime dt = DateTime.ParseExact(match2.Groups["time"].Value, "yyyyMMddHHmm", provider);
switch (region)
case "eu" :
dt.AddHours(1);
break;
case "is":
dt.AddHours(-1);
break;
dateTime.Add(dt); -
Extract x amount of words from a string
hi all just wondered if some can help me with this
String mySting = "This is a test String"
getInput(); // this method returns a string and works
getNoOfWordsInputted(); // returns int of words in the stringthis is where I need the help
I now need to extract getNoOfWords inputted from myString
ie such that if I input "this is " true will be returned
I can implment the following
if (getInput.equals(myString)){
// do Something
}Still not quite sure what you're after, but if you want to see if the target string starts with a candidate substring, just use the startsWith method.
if (example.startsWith(sub)) ...
or, you can still use the indexOf method, just check for a return value of 0, meaning the index of was at the beginning of the string.
if (example.indexOf(sub) == 0) ... -
Creating new String using only specific set of chars from another String
I've performance troubles doing this task:
I have a very long String A (up to 1 million character length)
This String contains different characters.
I need to create a String B containing only specific characthers (with a defined character code)
An example:
String A: [80]='P' [65]='A' [71]='G' [69]='E'For example I want to extract only character 65 and 71
String B: [65]='A' [71]='G'I already did the code to do this, (it's quite simple) but I think I have some very big performance issues, and I suppose I can do this task much more quickly!!
String out = "";
for (counter = 0; counter < text.length(); counter++) {
char currentchar = text.charAt(counter);
int currentvalue = (new Integer(currentchar)).intValue();
switch (currentvalue) {
case 65:
char[] newstring = new char[1];
newstring[0] = currentchar;
out += new String(newstring);
break;
case 71: //
break;
// other cases
default:
// nothing to do...
}Can you suggest me something to improve the performances?
Thank you!If you've got a number of characters in your acceptance set I'd use indexOf, and I'd probably use StringCharacterIterator. Mind you, with a million characters I'd probably not load them all at once anyway, but process them as streams.
StringBuffer out = new StringBuffer(s.length() / 5); // allocate plenty
StringCharacterIterator it = new StringCharacterIterator(s);
for(char c = it.first(); c != CharacterIterator.DONE; c = it.next())
if("AG".indexOf(c) >= 0)
out.append(c);
return c.toString(); -
Checking for an element in a string from another string
Hi Guru's,
I have 2 comma seperated strings. Say like this.
a VARCHAR2(100) := '1,2,3,4,5,6,7,8,9,10';
b VARCHAR2(100) := '2,6,9';
My requirement is like I want to check the string a, whether it has any of the element in b. I am trying to use the regular expression. But I was not able to do it.
Kindly help me.
Regards,
VJSQL> var cur refcursor
SQL> declare
a varchar2 (100) := '1,2,3,4,5,6,7,8,9,10';
b varchar2 (100) := '2,6,9';
begin
open :cur for 'select column_value common
from table (sys.dbms_debug_vc2coll (' || a || ') multiset intersect sys.dbms_debug_vc2coll (' || b || '))';
end;
PL/SQL procedure successfully completed.
SQL> print
COMMON
2
6
9
3 rows selected. -
labview 6i. Using sr785 instrument.
Two ways. Use Fract/Exp to Number function on the Strin>Strin Number Conversion palette. It accepts both individual or strin array inputs. Wire your string array in an get an array of doubles out. You can also use Scan From String on the String palette inside of a for loop. The for loop will autoindex the string array in and autoindex an array of doubles out.
Attachments:
string_to_double.jpg 10 KB -
How to extract from a string ?
Hello , I have this string and I need to extract 4 parts (in bold) from the string , my string is :
'(invoice) dear client : tom cruise you Buy *408* from MENA.CA @ *6.93* 01/10/09 watheeqa'
What is the best technique to do that?
ThanksHi,
oais wrote:
Hello , I have this string and I need to extract 4 parts (in bold) from the string , my string is :
'(invoice) dear client : tom cruise you Buy *408* from MENA.CA @ *6.93* 01/10/09 watheeqa'
What is the best technique to do that?
ThanksThat depends on how you know the 4 parts are what you showed, and not
'<b>(invoice) dear client: tom</b> cruise you Buy 408 from MENA.CA @ 6.93 01/10/09 watheeqa'
or
'<b>(invoice)</b> dear client: <b>tom cruise</b> you Buy 408 from MENA.CA <b>@</b> 6.93 01/10/09 <b>watheeqa</b>?'
or
'(invoice) dear client: <b>tom cruise</b> you Buy 408 from MENA.CA @ 6.93 <b>01/10/09 watheeqa</b>'
Will there always be exactly four parts you need to pick? -
How to extract an integer or a float value from a String of characters
Hi i have a problem getting to a float value within a string of characters..
for instance the string is
"numberItem xxxxxxxxx 700.0" (each x is a space..the forum wouldnt let me put normal spaces for some reason)
how do i store 700.0 in a float variable
remember the string is obtained from an inputfile
so far i got the program to store the inputfile data line by line in a String array..i tried tokenizing the string to get to the the float value but since i have mulitple spaces within my string, the token method only gets "numberItem" from the above String
This is all i have so far:
String c;
String Array[] =new String[g]; (i used a while loop to obtain g(the nubmer of lines in the file))
while((c=(cr.readLine()))!=null)
Array[coun]=c;
it would be reallllllllllllllllllllllllllllllllllllllly easy if there was a predefined method to extract numeric values from a string in java..
Edited by: badmash on Feb 18, 2009 5:50 PM
Edited by: badmash on Feb 18, 2009 5:50 PM
Edited by: badmash on Feb 18, 2009 5:55 PMbadmash wrote:
Hi i have a problem getting to a float value within a string of characters..
for instance the string is
"numberItem xxxxxxxxx 700.0" (each x is a space..the forum wouldnt let me put normal spaces for some reason)
with the space included
how do i store 700.0 in a float variable
remember the string is obtained from an inputfile
so far i got the program to store the inputfile data line by line in a String array..i tried tokenizing the string to get to the the float value but since i have mulitple spaces within my string, the token method only gets "numberItem" from the above StringHuh?
Not true.
Anyway why not use string split, split on spaces and grab the last element (which by the format you posted would be your 700.0)
Then there is the Float.parseFloat method.
It is easy.
And another thing why not use a List of Strings if you want to store each line? (And why did you post that code which doesn't really have anything to do with your problem?) Also in future please use the code formatting tags when posting code. Select the code you are posting in the message box and click the CODE button. -
select * from v$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
PL/SQL Release 11.1.0.7.0 - Production
CORE 11.1.0.7.0 Production
TNS for Linux: Version 11.1.0.7.0 - Production
NLSRTL Version 11.1.0.7.0 - ProductionI want to extract xyz_xyz,abc_abc words from the string ' select * from TEMP_TABLE where trunc(xyz_xyz) = ''xyz'' and trunc(abc_abc) = ''abc'') '
i have tried with this query...
select regexp_substr('select * from TEMP_TABLE where trunc(xyz_xyz) = ''xyz'' and trunc(abc_abc) = ''abc'')', 'trunc[^'''']+''') from dual
can some one help me on this?
Thanks,
MikeHi, Mike,
Mike wrote:
I apologize for this..
create table TEMP_TABLE ( col1 varchar2(10),col2 varchar2(10));
insert into TEMP_TABLE values(' xyz ','abc ');
insert into TEMP_TABLE values(' xyzxyz ','abcabc ');
insert into TEMP_TABLE values(' xyz123 ','abc546 ');
insert into TEMP_TABLE values('xyz','abc');
commit
select * from TEMP_TABLE where trim(col1) ='xyz' and trim(col2) ='abc'
desired output
col1,col2
So the correct output is one row, containing these 9 characters
col1,col2which do not appear in the table. is that right?
How is that output related to the data that is in the table? Do you want that output to appear if there are any rows where TRIM (col1) = 'xyz' and TRIM (col2) = 'abc' (for example, either of these two rows from you sample data:
insert into TEMP_TABLE values(' xyz ','abc ');
insert into TEMP_TABLE values('xyz','abc');), and would you want the result set to contain no rows if the table contained no row like that?
If so,
SELECT DISTINCT
'col1,col2' AS desired_output
FROM temp_table
WHERE TRIM (col1) = 'xyz'
AND TRIM (col2) = 'abc'
;I hope this answers your question.
I have a feeling that it doesn't, or perhaps you have more than one question, since this your earlier messages seemed to have something to do with locating text that was surrounded by single-quotes, and the sample data you posted doesn't contain any single-quotes. -
Calling a TextFields get method from another class as a String
This is my first post so be kind....
I'm trying to create a login screen with Java Studio Creator. The Login.jsp has a Text Field for both the username and password. JSC automatically created get and set methods for these.
public class Login extends AbstractPageBean
private TextField usernameTF = new TextField();
public TextField getUsernameTF() {
return usernameTF;
public void setUsernameTF(TextField tf) {
this.usernameTF = tf;
private PasswordField passwordTF = new PasswordField();
public PasswordField getPasswordTF() {
return passwordTF;
public void setPasswordTF(PasswordField pf) {
this.passwordTF = pf;
My problem is in trying to call these methods from another class and return the value as a string.
Any help on this matter would be greatly appreciated.the method returns the textfield, so you just need to get its text
import java.awt.*;
class Testing
public Testing()
Login login = new Login();
System.out.println(login.getUsernameTF().getText());//<----
public static void main(String[] args){new Testing();}
class Login
private TextField usernameTF = new TextField("Joe Blow");
public TextField getUsernameTF() {
return usernameTF;
} -
How to Extract particular field from a string ( Mapping)
how to exteract the particular field from the given string:
ProcessEmp this element has a below string subfields.
<ProcessEmp><?xml version="1.0" encoding="utf-8" standalone="no"?>
<Employee PersonnelNumber="11111" FirstName="String" MiddleName="String" LastName="String" Department="String" Group="" SapUserID="10flname" EmailAddress="[email protected]" DefaultPassword="*" Status="Success" /></ProcessEmp>
how to extract only PersonalNumber, department, EmailAddress from above ProcessEmp into 3 diff fields.
Thanks
dhanush.Hi,
You are receiving XML message within a field. To access a particular field from that XML message, you could create a User Defined Function, as suggested by many already.
You could write UDF using some of the String operation functions. This could include following:
1. If you need to access field Employee PersonnelNumber, you could get last index of that within string using function lastIndexOf(String str). Pass string "Employee PersonnelNumber="" for this function.
2. This function would return an index of rightmost occurance of this string.
3. after this you could get the index of next occurance of ", as the value of field is within quotes. You could use function indexOf(int ch, int fromIndex) for getting the same. You would pass Character as " and index as the one received by previous function.
4. Now you have index for starting and ending point of value string for desired field.
5. After this you could use substring(int beginIndex, int endIndex) function by passing first and second index values to retrieve the needed string, which contains value of field.
Hope this would be helful.
Thanks,
Bhavish
Reward points if comments found helpful:-) -
Hi,
I am curious if there is an easy way to extract an int value from a String.
For example, "Rb23" to get 23. The length of the part in front of the integer is variable.
Thanksthis seems to work:
public int extract(String s) {
String result = "";
char c[] = s.toCharArray();
int j = c.length-1;
if (!Character.isDigit(c[j])) {
return 0;
do {
result+=c[j--];
} while (j > 0 && Character.isDigit(c[j]));
return Integer.parseInt(new StringBuffer(result).reverse().toString());
}it will return 0 if no numbers are found at the end of the string
Maybe you are looking for
-
How to end my Adobe account?
I would like to end my Adobe account but I don't know how.
-
Logging into InDesign after renewing membership
I have renewed my creative cloud membership but I still can't log into InDesign. I click "try again" and wait the required 15 minutes, but nothing. Can this process be expedited at all?
-
I am replacing my ipod touch today. I backed up the apps into itunes and they now sit in itunes>library>apps. How can I transfer them to the new ipod touch? Everytime I attempt to move the apps, i get a red circle w/ line thru it and I can't do an
-
Bill print information message
Hi, I'm getting this information message in Bill Preview option of transaction code EA40. Message no. EB152 (Test print: Cannot be archived) Why is this happening?
-
Update-alternatives for arch ?
Hi all, i'm trying to install JDK 7 and use it instead of JDK 6, in ubuntu i could just install both and choose which to use using update-alternatives command. But in arch i can't, note that i already downloaded the binary package for JDK 7 so i don'