I have 2 Java strings
1st String is a series of names, colons, and numbers
ie) Name1:13:Name2: 4526:Name3:789: Name4:3729:Name 5:6:Name6: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
3 3562 JosAH 11,448
Recognized Expert MVP
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
I have 2 Java strings
1st String is a series of names, colons, and numbers
ie) Name1:13:Name2: 4526:Name3:789: Name4:3729:Name 5:6:Name6: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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 values and separators
class
{
private string globalvar = "";
private void manipulate (whattodo ) //substring, join, etc....
|
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 ((someString.IndexOf("something1",0) >= 0) ||
((someString.IndexOf("something2",0) >= 0) ||
|
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 substring
before a pattern), AFTER (return substring after a pattern), and
BETWEEN (return substring between 2 patterns).
My questions are:
1. Can any tell me how I can implement such functionality in C#?
2. Is it possible to add/include function...
|
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 substrings need
be replaced, or one character needs be changed, what shall I do? Is it
better to convert strings to UCS-32 before manipulation?
But on Windows, wchar_t is 16 bits which isn't enough for characters
which can't be simply encoded...
|
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 line and not the others. If i use re module, how to compile
the expression to do this? I tried the re module and using simple
| |
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 20.02.2006 etc...
And I want to replace the /,.etc character with - (as 20-02-2006)
|
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 string”
This is very urgent. Please help
|
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 anywhere else and is only used by this behind-the-scenes object to provide the database manipulation object with a connection string.
Does my connection string pose a security problem when it is inside the code like this?
Or are connection strings...
|
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.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |