在PowerShell脚本中,如何获取名称中包含括号的环境变量的值?
更复杂的是,一些变量的名称包含括号,而其他变量的名称没有括号.例如(使用cmd.exe):
C:\>set | find "ProgramFiles"
CommonProgramFiles=C:\Program Files\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
ProgramFiles=C:\Program Files
ProgramFiles(x86)=C:\Program Files (x86)
Run Code Online (Sandbox Code Playgroud)
我们看到%ProgramFiles%的不一样了%ProgramFiles(x86)%.
我的PowerShell代码以一种奇怪的方式失败,因为它在括号后忽略了环境变量名称的一部分.由于这恰好匹配了一个不同但现有的环境变量的名称,我不会失败,我只是得到了错误变量的正确值.
这是PowerShell脚本语言中的一个测试函数,用于说明我的问题:
function Do-Test
{
$ok = "C:\Program Files (x86)" # note space between 's' and '('
$bad = "$Env:ProgramFiles" + "(x86)" # uses %ProgramFiles%
$d = "${ Env:ProgramFiles(x86) }" # fail (2), LINE 6
# $d = "$Env:ProgramFiles(x86)" # fail (1)
if ( $d -eq $ok ) {
Write-Output "Pass"
} elseif …Run Code Online (Sandbox Code Playgroud) 我希望我的Android对话框和/或警报有时在屏幕的最顶部对齐,而不是简单地在中心.这可能吗?给出精确的xy坐标怎么样,这可能吗?
当我试图在IE中使用documnet.write插入iframe时,我获得了成功.但是,之后的任何html代码都不会被执行.
document.write("<div>Hello</div><iframe ..../><div>Bye Bye</div>");
Run Code Online (Sandbox Code Playgroud)
这里"Bye Bye"字符串未执行.
要立即检查,您可以输入您的浏览器网址
javascript:document.write("<div>Hello</div><iframe ..../><div>Bye Bye</div>");
Run Code Online (Sandbox Code Playgroud)
经过反复试验后,我发现如果我按照以下方式关闭iframe标签,它就能正常工作.
<iframe ...></iframe> instead of <iframe ... />
Run Code Online (Sandbox Code Playgroud)
现在的问题是:"我没有任何机会改变<iframe ../>到<iframe .. ></iframe>".寻找你的好意见.
我做了一个SingleItemAdapter扩展ArrayAdapter,这个定制的适配器用于ListView.
在这里SingleItemAdapter,我做了一些数据库的东西,所以我想在getView()初始化GUI的方法中抛出异常.
但public View getView(int position,View convertView,ViewGroup parent)抛出异常会得到Exception Exception is not compatible with throws clause in ArrayAdapter.getView(int, View, ViewGroup)
ArrayAdapter,BaseAdapter,Adapter不会抛出异常,为什么呢?
在我的Application.Resources我有以下Storyboard定义.
<Application.Resources>
<!--Storyboard animation for fading out a UI element-->
<Storyboard x:Key="FadeOutAnimation">
<DoubleAnimation From="1"
To="0"
Duration="0:0:0.25"
Storyboard.TargetProperty="Opacity"
AutoReverse="False" />
</Storyboard>
</Application.Resources>
Run Code Online (Sandbox Code Playgroud)
在代码隐藏中,TextBlock当用户点击它时,我会使用它来淡出一些s.
// Get the storyboard from application resources
Storyboard sb = (Storyboard)App.Current.Resources["FadeOutAnimation"];
// Setup the animation target for fade out
Storyboard.SetTarget( sb.Children.ElementAt( 0 ) as DoubleAnimation, myTextBlock );
// Set the animation completed handler
sb.Completed += ( s, e1 ) => {
// Stop the Storyboard
sb.Stop();
// Hide the TextBlock
myTextBlock.Visibility = …Run Code Online (Sandbox Code Playgroud) 我最近在我正在处理的现有代码库中运行了以下代码段,并添加了您在那里看到的注释.我知道这段特殊的代码可以重写为更清晰,但我只是想知道我的分析是否正确.
java会创建一个新的类声明并将其存储在perm gen空间中,以便每次调用此方法,还是会知道重用现有的声明?
protected List<Object> extractParams(HibernateObjectColumn column, String stringVal) {
// FIXME: could be creating a *lot* of anonymous classes which wastes perm-gen space right?
return new ArrayList<Object>() {
{
add("");
}
};
}
Run Code Online (Sandbox Code Playgroud) 我试图更多地了解AWT/Swing的Window类的dispose()函数及其作用.想象一下以下一系列事件:
A是GC后,B是否使用了留下的非处置资源?
此外,对于Window衍生Z,如果有很多Z实例,JRE是否能够在它们之间重用窗口资源?
java user-interface garbage-collection dispose memory-management
我的问题是双重的.
1)我正在编写一个论坛,我无法弄清楚如何为论坛用户存储时区.他们将能够设置他们的时区,并相应地修改论坛上的所有日期.我是否必须创建一个带有时区名称和数字的数据库表来调整服务器时间?.NET是否在某处内置了时区支持?
2)一旦我弄清楚如何存储用户的时区,然后将DateTime对象修改到正确的时间,我就需要一种简单的方法将这个修改后的日期传递给MVC中的视图.例如,我有以下代码:
List<Topic> topics = board.Topics.OrderByDescending(x => x.Replies.Any()
? x.Replies.OrderBy(y => y.PostedDate).Last().PostedDate
: x.PostedDate).ToList();
Run Code Online (Sandbox Code Playgroud)
此topics对象作为视图模型对象的一部分传递给视图.视图循环Model.Topics显示主题列表.问题是我不想在视图中进行时区修改,因为我认为这对视图负有太大的责任.有没有办法在LINQ查询中修改主题日期?
提前致谢!
我想在 android 画布上为单个 Path 设置动画。
public class MyView extends View {
private Path paths[];
protected void onDraw( Canvas canvas ) {
Paint paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth( 8 );
paint.setColor(Color.BLUE);
Path path = new Path();
path.moveTo(75, 11);
path.quadTo(62, 87, 10, 144);
canvas.drawPath( path, paint );
paths[0] = path;
path.reset();
path.moveTo(50, 100);
path.lineTo(150, 200);
canvas.drawPath( path, paint );
paths[1] = path;
}
}
Run Code Online (Sandbox Code Playgroud)
现在我有了路径 [],我想分别为每个路径设置动画。我希望它改变 alpha 就像它在增长一样。起初只有一个小点,然后它长成一条线,重复。
可以做到吗?
如何?
我正在通过SSH从Mac OS X中的终端应用程序连接到运行cygwin的桌面.我已经在cygwin端启动了屏幕并可以通过SSH会话连接到它.此外,我在.screenrc文件中有以下内容:
bindkey -k k1 select 1 # F1 = screen 1
bindkey -k k2 select 2 # F2 = screen 2
bindkey -k k3 select 3 # F3 = screen 3
bindkey -k k4 select 4 # F4 = screen 4
bindkey -k k5 select 5 # F5 = screen 5
bindkey -k k6 select 6 # F6 = screen 6
bindkey -k k7 select 7 # F7 = screen 7
bindkey -k k8 select 8 # F8 …Run Code Online (Sandbox Code Playgroud) android ×3
java ×3
.net ×1
animation ×1
asp.net-mvc ×1
browser ×1
c# ×1
canvas ×1
cygwin ×1
dialog ×1
dispose ×1
escaping ×1
gnu-screen ×1
iframe ×1
javascript ×1
linq ×1
location ×1
path ×1
positioning ×1
powershell ×1
silverlight ×1
ssh ×1
wpf ×1