RE: searching for a string of characters after another string of characters

Reading the entire file into an array is rarely a good idea, but if you
insist on doing it, then you have to realize that each element of the array
is going to be exactly one line of the file.  So, "hostname XXXXX\n" is
going to be one element unless you explicitly extract using a split or
regex.

-----Original Message-----
From: Grossner, Tim X. (AIT) [mailto:tg1761@sbc.com]
Sent: Thursday, July 12, 2001 3:28 PM
To: Mooney Christophe-CMOONEY1
Subject: RE: searching for a string of characters after another string
of characters


No, I have already extracted the line, and i put it into an array...the
problem is that its ending up as the only element of the array. IE, print
@hostname returns "hostname XXXXX". I only want the XXXXX.

-----Original Message-----
From: Mooney Christophe-CMOONEY1 [mailto:CMOONEY1@motorola.com]
Sent: Thursday, July 12, 2001 1:11 PM
To: Grossner, Tim X. (AIT)
Subject: RE: searching for a string of characters after another string
of characters


If i understand you correctly, you're trying to extract exactly one line out
of a file.

I would do this:

while (<IN>)
{
	if (/^hostname\s+(\S+)$/) # or some other regex derivative
	{
		$hostname=$1;
		last;
	}
}

-----Original Message-----
From: Grossner, Tim X. (AIT) [mailto:tg1761@sbc.com]
Sent: Thursday, July 12, 2001 3:03 PM
To: beginners@perl.org
Subject: searching for a string of characters after another string of
characters


How would I do this:

file A contains a line of characters always looking like "hostname XXXXX". 
I want to take the XXXXX and assign that to a scalar...I tried making an
array out of it by using grep to search for the line starting with
"hostname", but then the  one and only element of the array is "hostname
XXXXX" and I cant figure out how to extract the XXXXX out...

Any help would be greatly appreciated.


__________________________________________________
Tim Grossner
Field Operations Manager        CCNA, MCP, A+
Southwestern Bell Datacom
voice - 217-522-7564
pager - 217-467-3148
cell - 217-971-3060
data - tim.x.grossner@ameritech.com
0
CMOONEY1
7/12/2001 8:41:52 PM
perl.beginners 29388 articles. 4 followers. Follow

0 Replies
936 Views

Similar Articles

[PageSpeed] 44
Get it on Google Play
Get it on Apple App Store

Reply:

Similar Artilces:

FW: searching for a string of characters after another string of characters
If i understand you correctly, you're trying to extract exactly one line out of a file. I would do this: while (<IN>) { if (/^hostname\s+(\S+)$/) # or some other regex derivative { $hostname=$1; last; } } -----Original Message----- From: Grossner, Tim X. (AIT) [mailto:tg1761@sbc.com] Sent: Thursday, July 12, 2001 3:03 PM To: beginners@perl.org Subject: searching for a string of characters after another string of characters How would I do this: file A contains a line of characters always looking like "hostname XXXXX". I want to take the...

searching for a string of characters after another string of char acters
How would I do this: file A contains a line of characters always looking like "hostname XXXXX". I want to take the XXXXX and assign that to a scalar...I tried making an array out of it by using grep to search for the line starting with "hostname", but then the one and only element of the array is "hostname XXXXX" and I cant figure out how to extract the XXXXX out... Any help would be greatly appreciated. __________________________________________________ Tim Grossner Field Operations Manager CCNA, MCP, A+ Southwestern Bell Datacom voice...

Replace a space character in a string with another character
Hello, I need to replace all space characters within a specific string with the character % EG hello grant Result needs to be hello%grant Many thanks GrantGrant Krieger You can use Replace method. string str = "hello grant"; str = str.Replace(' ','%'); If you're concerned with performance, use Regular Expression(Regex) rather than string class.Jason Huh MSCD,MCDBA,MSCE...

How do I parse a string character by character?
Hi, I have a string i.e) 156.5 I need to be able to parse the string one character at a time and write the character value to an array Pseudo Code: For i=1 To String.Length strImageArray(i) = stringCharacter Next Hope this makes sense! Thanks, Chris TrystrImageArray = myString.ToCharArray...

reading character for character in a string
Hi, How can I read character for Character in a String or should I use split. example. strName = "Holland_Amsterdam" I need the word after the _  in another string variable. How can I do this. with kind regards, Alexander Since you know you have to split @ '-', use Split and get balues to array and use it!Sreedharhttp://www.w3coder.orgweblog http://weblogs.asp.net/skoganti...

searching character in a string
for example i have a string = "somefile_abc_00001111.jpg" ... how can i trim the string to make it somefile_abc.jpg? is there a function that can search the string starting from the right? this would be easy if there's only one instance of "_". my problem would be how can i get the last instance of "_" so i can trim from the startindex of the string up to the index of last instance of "_"mess with the best...die like the rest I think the method you're looking for is string.LastIndexOf("_") That will return the position of the last &qu...

RE: RE: A question about strings and hexadecimal numbers of special characters
Thanks Tim. Your answer solves many problems to me. But I have a further question. Sometimes a question mark apears in the middle of a string like that: $string = "/cgi-bin/search.pl?term=who?&lang=english"; where "who?" is a unit and the question mark is part of it. Although I try to escape the question mark in "who?" and I get its hexadecimal number, I don't get the expected result because it's interpreted as a second quoestion mark in the whole string. Regards, - Oriol - ___________________________________________________...

splitting a string of characters and numbers into separate strings
Hi,  I was looking at the Split() function in vb.net but don't know if there's an easier way to do this.  I have a string that is alphanumeric.  It starts with alphabetical characters and ends with integers.  The length varies from one record to another.  I had to concatenate the two to have them appear together in a dropdown list.  However, when a user selects it, I need to split it in two different strings, one that holds just the alphabetical characters and one that has just the integer values.  Is there an easier way than just going through the...

Select part of character string based on a character
I have data in a column that starts with 1-4 characters followed by a dash then followed by an number of characters (ex: EU-Surgery). How do I select everything to the right of the dash when the number of characters to the left of the dash varies? One approach I have taken with that is this: DECLARE @myString varchar(50) SELECT @myString = 'EU-Surgery' SELECT REVERSE(LEFT(REVERSE(@myString),CHARINDEX('-',REVERSE(@myString))-1)) TerriTerri MortonEngagement Manager, NeudesicHow to ask a question I have the following: SELECT REVERSE(LEFT(REVERSE(Col01...

Search String with Multiple Characters
I am trying to search over a string (user inputs a word in a textbox) and determine if there are any vowels is it.  Then if there is then I replace them with a wildcard. The Replace function works fine by allowing me to replace multiple characters at once with "[aeiou]" inserted in SearchFor location. However the Instr and IndexOf functions do not accept "[aeiou]"  only "a" for example.  I am using one of these functions to identify the vowels in the word to then determine the direction whether to replace or ignore and do something else. W...

How to search string value if it contains another string (C#)
I have two string variables. And I want to find out if the value of the second one is part of the first. Please can you give me advice how to do that. Perhaps .net Framework has a system method which can do that. Thanks for help in advance.     You can either use the String.Contains() or String.IndexOf() methods to check if a string exists within another stringThe contains method returns a boolean and the indexof returns the starting index of the string so -1 denotes not found and anything > 0 means founde.g. string val1 = "hello world"; stri...

How to take every characters from string except last character
Hai friends... if user enter in texbox....there id and gender.....how to take id and gender...........separately for eg....... 04Q123M  here 04Q123 is id and M is Male Gender 03C117F here 03C117 is id and F is FeMale Gender Help me.........Winners Never QuitQuitters Never Win You could do something like:string idAndGender = textboxName.Text;if(idAndGender.Length > 0){string id = idAndGender.Substring(0, (idAndGender.Length - 1))string gender =  idAndGender.Substring((idAndGender.Length - 1), 1)}   Ignore me. The answer was already posted above...

Replace string with list of strings via character changes
I want to replace all the o's in a string with x's or y's and all the a's in a string with u's or v's. Example: given string "foobar", the output would be this list of strings fxxbur (change both o's to x, and the a to u) fxxbvr (both o's to x, a to y) fxybur (first o to x, second to y, and the a to u) fxybvr (and so on...) fyxbur fyxbvr fyybur fyybvr What's the best subroutine to do this? I've got some ideas, but they're all fairly complex. Reason I'm doing this (if anyone cares): I want to ASCII-ify the geonames ...

Search one character against one string
--531fe97b_6b8b4567_ca8 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi there, I got a wired bug with the following perl script: 35 # return non-negative value if particular character is in string array 36 # otherwise, return -1 sub is_in_string { 38 # @s: string array, $c: character 39 # passing array into sub 40 my @s = @_[0]; my $c = $_[1]; 41 for my $i (@s) { if ($c eq $i) {return 1} } 42 return -1; 43 } 44 my @ar = qw(t d s); 45 my $c = "d"; 46 my $res = &is_in_string( @a...

Web resources about - RE: searching for a string of characters after another string of characters - perl.beginners

Dilbert (character) - Wikipedia, the free encyclopedia
Dilbert is a fictional character and the main character and protagonist of the Dilbert comic strip . He is a white collar office worker who has ...

Why Coke Is Sticking With These Giggling Characters For Chinese New Year
... it wanted to find a symbol that would have that same long-term appeal in China, so it went back to the archives. It brought out some characters ...

Cut ‘Star Wars: The Force Awakens’ scene reveals a new character’s major powers
... one of the many Star Wars movies that will hit cinemas by the end of this decade. One of the best things about the movie was its new characters ...

A deleted scene from 'Star Wars: The Force Awakens' reveals a new character's awesome power
Maz Kanata's castle plays a larger part in "The Force Awakens" than the character herself, but she's more powerful than you realized watching ...

Nintendo promises “big characters” like Mario coming to smartphones this year
... by 2017. The first Nintendo game for smartphones, though, was delated until March, and worse, features none of Nintendo’s best known characters. ...

‘Jessica Jones’ Showrunner On Season 2: “I Just Want It To Be About Her Character” – TCA
Given that Daredevil was renewed two weeks after the show’s April premiere, you’d be forgiven for thinking that its successor, the hugely acclaimed ...

'Five Nights At Freddy's World' New Gameplay Teasers Reveal Story Clues And Pig Boss Character
"Five Nights At Freddy's World" releases next month, and new teasers are here to hype up the incoming launch. Check out the new boss and story ...

Black Desert Online gets a second beta and a standalone character creator
... since the first test, will be announced closer to the time. One of the big selling points of Black Desert is its ridiculously detailed character ...

Toyota turned the Prius' parts into anime characters
... car manufacturer, how would you make your technology accessible to the public? Toyota has a rather strange answer: turn it into anime characters. ...

Netflix open to more Marvel shows: Any character could get spin-off - EW.com
Skip to main content X TV TV Recaps Movies Music Books Gaming Video Recaps The Royals Angie Tribeca Billions Downton Abbey Galavant The Good ...

Resources last updated: 1/21/2016 8:55:11 AM