"some text \\computername.example.com\admin$ ".
How do I do the substitution so my final result is just “computername”
My question does not seem to know how to escape the two backslashes. For the sake of simplicity, I would rather not Use regular expressions:)
Edit: It actually looks like stackoverflow also has a problem with double backslashes, it should be a double backslash, not a single backslash
< /div>
$test = "some text \\computername.example.com\admin$"
$test.Split('\')[2]. Split('.')[0]
A very simple test shows that the split speed on my machine is slightly faster than its value:
12:35:24 |(19)|C:\ PS>Measure-Command {1..10000 | %{'some text \\computername.example.com\admin$'.Split('\')[2] .Split('.')[0]}}
Days: 0
Hours: 0
Minutes: 0
Seconds: 1
Milliseconds: 215
Ticks: 12159984
TotalDays: 1.40740555555556E-05
TotalHours: 0.000337777333333333
TotalMinutes: 0.02026664
TotalSeconds : 1.2159984
TotalMilliseconds: 1215.9984
12:35:34 |(20)|C:\ PS>Measure-Command {1..10000 |% {'Some text \\computername\admin$' -replace'\\\\(\w+)\\(\w+)\$','$1'}}
Days : 0
Hours: 0
Minutes: 0
Seconds: 2
Milliseconds: 335
Ticks: 23351277
TotalDays: 2.70269409722222E-05
TotalHours: 0.000648646583333333
TotalMinutes: 0.038918795
TotalSeconds: 2.3351277
TotalMilliseconds: 2335.1277
I have a string consisting of< p>
"some text \\computername.example.com\admin$".
How do I replace so my final result is just “computername “
My question does not seem to know how to escape the two backslashes. For the sake of simplicity, I would rather not use regular expressions:)
Edit: actually looks like stackoverflow There is also the problem of double backslashes, it should be a double backslash instead of a single backslash
First of all, the regular expression method proposed There is absolutely nothing wrong. But, if you are not interested in it, please check:
$test = "some text \\computername.example.com\admin$"
$test.Split('\')[2].Split('.')[0]
A very simple test shows that the split speed on my machine is slightly faster than its value:
12:35:24 |(19)|C:\ PS>Measure-Command {1..10000 | %{'some text \\computername.example.com\admin$'.Split('\')[2].Split('.')[0]}}< br />
Days: 0
Hours: 0
Minutes: 0
Seconds: 1
Milliseconds: 215
Ticks: 12159984< br />TotalDays: 1.40740555555556E-05
TotalHours: 0.000337777333333333
TotalMinutes: 0.02026664
TotalSeconds: 1.2159984
TotalMilliseconds: 1215.9984
< br />12:35:34 |(20)|C:\ PS>Measure-Command {1..10000 | %{'Some text \\computername\admin$' -replace'\\\\(\w+) \\(\w+)\$','$1'))
Days: 0
Hours: 0
Minutes: 0
Seconds: 2
Milliseconds: 335
Ticks: 23351277
TotalDays: 2.70269409722222E-05
TotalHours: 0.000648646583333333
TotalMinutes : 0.038918795
TotalSeconds: 2.3351277
TotalMilliseconds: 2335.1277
WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 5446 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC