473,463 Members | 1,494 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

String Manipulation

I have 2 Java strings

1st String is a series of names, colons, and numbers
ie) Name1:13:Name2:4526:Name3:789:Name4:3729:Name5:6:N ame6:44

2nd String is a name
ie) Name2

I need to get the number associated with that name.

So I need a java function that traverses that first string, looks for the 2nd string, and returns the number that is directly after it. Thus in my example, I would pass the function String1 and String2 and it would return the number 4526.

Can someone help? My string manipulation skills in java are sub par...I know how to do it in sql, but not java.

-Jason
May 24 '07 #1
3 3535
JosAH
11,448 Expert 8TB
Have a look at the API documentation for the String.indexOf() method. A
bit of fiddling with it and the Integer.valueOf() method will do the job.

If you're feeling adventurous you can check out Java's regular expression support
too, but I'd recommend the first approach first.

kind regards,

Jos
May 24 '07 #2
prometheuzz
197 Expert 100+
I have 2 Java strings

1st String is a series of names, colons, and numbers
ie) Name1:13:Name2:4526:Name3:789:Name4:3729:Name5:6:N ame6:44

2nd String is a name
ie) Name2

I need to get the number associated with that name.

So I need a java function that traverses that first string, looks for the 2nd string, and returns the number that is directly after it. Thus in my example, I would pass the function String1 and String2 and it would return the number 4526.

Can someone help? My string manipulation skills in java are sub par...I know how to do it in sql, but not java.

-Jason
Have a look at the split(...) method from the String class: it returns an array of Strings. You can split it on the ":". Then your names will be on indexes 0,2,4,...,n and the associated numbers will be on 1,3,5,...,n+1. This of course assumes your names are nicely increasing every time!

Have a look at the API docs to see how the method works:
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html

Good luck.
May 24 '07 #3
if you know sql then u'll understand the Map interface in the java api. just look for a class that implements the interface, use the instantiate one of them and you're rolling.
May 25 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Dim | last post by:
I found that C# has some buggy ways to process string across methods. I have a class with on global string var and a method where i add / remove from this string Consider it a buffer... with some...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
29
by: zoro | last post by:
Hi, I am new to C#, coming from Delphi. In Delphi, I am using a 3rd party string handling library that includes some very useful string functions, in particular I'm interested in BEFORE (return...
4
by: WaterWalk | last post by:
Hello, I'm currently learning string manipulation. I'm curious about what is the favored way for string manipulation in C, expecially when strings contain non-ASCII characters. For example, if...
10
by: micklee74 | last post by:
hi if i have a some lines like this a ) "here is first string" b ) "here is string2" c ) "here is string3" When i specify i only want to print the lines that contains "string" ie the first...
5
by: Niyazi | last post by:
Hi, Does anyone knows any good code for string manipulation similar to RegularExpresion? I might get a value as string in a different format. Example: 20/02/2006 or 20,02,2006 or ...
3
by: crprajan | last post by:
String Manipulation: Given a string like “This is a string”, I want to remove all single characters( alphabets and numerals) like (a, b, 1, 2, .. ) . So the output of the string will be “This is...
7
Frinavale
by: Frinavale | last post by:
I currently have a .NET application that has an object which passes a string (a connection string) as a parameter to another object that does database manipulation. This string isn't stored...
22
by: mann_mathann | last post by:
can anyone tell me a solution: i cannot use the features in standard c++ string classgh i included the string.h file but still its not working.
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.