I have email format like
iba#test.com
Expected output
#test.com
I need to remove the name after the mail id how can I do that I have tried str_replace but that does not give me a solution.
Please try like this :
let string = "iba#test.com"
const result = `#${string.split('#')[1]}`
using explode
$email= "iba#test.com"
$domain= explode("#",$email);
echo $domain[0]; // iba
echo $domain[1]; //test.com
Related
I'm learning Flutter/Dart and there is this check that i want to perform - to validate that a user who has entered an email should contain # in it
String myString = 'Dart';
// just like i can do the following check
myString.contains('a') ? print('validate') : print('does not validate')
// I want to do another check here
myString does not contain('#') ? print('does not validate'): print('validate')
Can someone suggest is there any inbuilt function to do such a thing.
Just simply put not ! operator (also known as bang operator on null-safety) on start
void main() {
String myString = 'Dart';
// just like i can do the following check
myString.contains('a') ? print('validate') : print('does not validate');
// I want to do another check here
!myString.contains('#') ? print('does not validate') : print('validate');
}
I'm new to the Lua .. I want to get the username , using string.match
That's like the way I use them
local text = 'hi my name #saleh and my friend #chris ..'
print(string.match(text, "(#[%a%d]+)"));
Result
#saleh
I want all the usernames
You want string.gmatch. Use it in a loop:
for name in text:gmatch "(#[%a%d]+)" do
print( name )
end
above answer not work
This code is exact
for name in text:gmatch "(#[%a%d]+)" do
print(name:sub(2, -1))
end
I am trying to split a string into individual characters.
The string I want to split: let lastName = "Kocsis" so that is returns something like: ["K","o","c","s","i","s"]
So far I have tried:
var name = lastName.componentsSeparatedByString("")
This returns the original string
name = lastName.characters.split{$0 == ""}.map(String.init)
This gives me an error: Missing argument for parameter #1 in call. So basically it does't accept "" as an argument.
name = Array(lastName)
This does't work in Swift2
name = Array(arrayLiteral: lastName)
This doesn't do anything.
How should I do this? Is There a simple solution?
Yes, there is a simple solution
let lastName = "Kocsis"
let name = Array(lastName.characters)
The creation of a new array is necessary because characters returns String.CharacterView, not [String]
I use PHP to process following input:
sam
99912222
tom
11122222
harry
12299933
sam
edward
harry
the 1st to 6th line are name and phone numbe. And the last three lines is the search query, if the name is not in the list(not have phone number,print not found), otherwise output the data. My code as follow:
<?php
$_fp = fopen("php://stdin", "r");
$list = array();
for($i = 0;$i<3;$i++){
$name = strtolower(fgets($_fp));
$phone = fgets($_fp);
$list["$name"] = $phone;
}
for($i = 0;$i<3;$i++){
$name = fgets($_fp);
if(array_key_exists($name,$list)){
echo "$name".'='."$list[$name]"."\n";
}else{
echo 'Not found'."\n";
}
?>
Excepted output should be sam = 99912222 Not found harry = 12299933
The output is sam = 99912222 Not found Not found. why these function doesn't work?
This is a problem from hackerrank.
I know if I use hashmap in java is easy to solve. But how can I solve this problem in PHP?
Many thanks
First, trim off whitespace by using trim(fgets($_fp)) everywhere instead of just fgets($_fp) -- that fixes things on my end at least.
Second, the code you pasted is missing the closing curly bracket on your second for loop.
Third, have fun with 30 Days of Code :-) (once you get the above straightened out you also need to have your code read in the number of entries at the beginning, and "Read the queries until end-of-file" at the end).
I have a string with multiple lines. For this example, my string will be this:
Name:Jaxo
Description:A person on Stackoverflow
Question:$this->questionName();
How could I get just, say, the 'Description'? I need everything after the description, ie 'A person on Stackoverflow'. I've tried a regex like this, but it doesn't work: /^Description:(.+?)\n/i
Any help is much appreciated!
Thanks
-Jaxo
This should work for you:
if (preg_match('/Description:(.+)/im', $subject, $regs)) {
$result = $regs[1];
} else {
$result = "";
}
Where $result is the Description name.
If there is a newline character separating each part of the label you could explode.
$array = explode("\n",$string); // separate params
$desc = explode(":",$array[1]); // separate description
This way you could get any of the parameters.
Try this:
$a="Name:Jaxo
Description:A person on Stackoverflow
Question:\$this->questionName();";
preg_match("/Description:([^\n]+)/i",$a,$m);
print_r($m);
Output:
Array ( [0] => Description:A person on Stackoverflow [1] => A person on Stackoverflow )