473,372 Members | 836 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

How to get the first word from a given string...

parajaganesh
How to get the first word from a given string in perl...
Oct 12 '07 #1
4 11187
KevinADC
4,059 Expert 2GB
The best way to get help on this forum with your questions is to post the code you have written so far to try and accomplish whatever it is you are doing. Posting a requirement with no code makes it seem like you are too lazy or unwilling to even try it yourself first, epecially when the question is such an easy one.

Beginning Perl
Oct 12 '07 #2
How to get the first word from a given string in perl...
Try this code, and modify as u required. i think this will enough for ur doubt.

$a="flintstones husband fred pal barney wife wilma pet dino";
if ($a) {
$a=~/^(.*?)\s/;
print $1;
}
Oct 13 '07 #3
KevinADC
4,059 Expert 2GB
Try this code, and modify as u required. i think this will enough for ur doubt.

$a="flintstones husband fred pal barney wife wilma pet dino";
if ($a) {
$a=~/^(.*?)\s/;
print $1;
}
We prefer that people show some effort before doing their code/work for them.
Oct 13 '07 #4
I would split each word using the space between each word as he splitter. Then I would place the shift of the new array into a scaler.
Oct 13 '07 #5

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

Similar topics

20
by: hagai26 | last post by:
I am looking for the best and efficient way to replace the first word in a str, like this: "aa to become" -> "/aa/ to become" I know I can use spilt and than join them but I can also use regular...
7
by: zjut | last post by:
I need to implement the method : round(String name, int index) The given string maybe the every type of float type, ( the msdn given the regax is that : integral-digits]exponential-digits]) ...
5
by: deko | last post by:
Is there an accepted or standard way to get a unique name given a string and the collection in which it needs to be unique? Should I use a HashTable? Other options? Here's a first crack: ...
2
by: shapper | last post by:
Hello, I want to remove the first word of a string. For example: MyString = "Hello World! How are you?" I need to create 2 string: MyString1 = "Hello"
2
by: Kelly B | last post by:
I tried to write a code which would reverse the order of words in a given string. I.e if Input String=The C Programming Language Output String=Language Programming C The Here is the code...
0
by: wildman | last post by:
What's the easiest way to return the first word from a string in vb.net? thanks for any help or information.
4
MrPickle
by: MrPickle | last post by:
I am tokenizing a line using a stringstream and a vector but the stringstream seems to be repeating the first word, here's my code: std::stringstream ss; std::vector<std::string> LineVec;...
2
by: whodgson | last post by:
The following code accepts a string from the user and swaps the first and last letters in each word. It prints out the original string incorrectly by dropping off the first letter of the first word....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.