我正在尝试使用正则表达式来提取文件标题中的注释.
例如,源代码可能如下所示:
//This is an example file.
//Please help me.
#include "test.h"
int main() //main function
{
...
}
Run Code Online (Sandbox Code Playgroud)
我想从代码中提取的是前两行,即
//This is an example file.
//Please help me.
Run Code Online (Sandbox Code Playgroud)
任何的想法?
我想在父div中的某个位置将4个div放在彼此旁边.所以div结构就是这个(我称之为maindiv最顶层的div):
<div>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
</div>
Run Code Online (Sandbox Code Playgroud)
现在我想在maindiv的左边设置文本"1"的div
现在我想在maindiv的左侧以50像素设置文本'2'的div
现在我想在maindiv的左侧以150像素设置div为文本'3'
现在我想在maindiv的左侧以200像素设置文本'4'的div
我认为:-)我已经尝试过所有可能的css结构,但遗憾的是它没有用.
有人有想法吗?
我有一个下拉菜单,用户选择一个国家/地区.这是一个必需的"领域".
在它旁边,有一个名为State的文本字段.如果用户选择US,则需要字段State.如果用户选择例如瑞典,则不需要国家,因为瑞典没有州.
示例代码:
<asp:DropDownList runat="server" ID="Country"></asp:DropDownList>
<asp:RequiredFieldValidator ControlToValidate="Country"
runat="server" Display="Static" ErrorMessage="Required field" />
<asp:TextBox runat="server" ID="State"></asp:TextBox>
<asp:CustomValidator ClientValidationFunction="DoesntGetFiredIfStateIsEmpty"
runat="server" Display="Static" ErrorMessage="Required field" />
<!-- SO, RATHER THIS TOGETHER WITH CONDITIONAL FIRING -->
<asp:RequiredFieldValidator ControlToValidate="State"
runat="server" Display="Static" ErrorMessage="Required field" />
Run Code Online (Sandbox Code Playgroud)
我向您提出的问题是:如果CustomValidator为空,我该如何进行防火验证?
或者说更简单:如何有条件地使RequiredValidator火灾?
或者最简单:如何在客户端启用/禁用RequiredValidator?
我有一个像这样的XML文件:
<Users>
<User>
<Adress Name="bbbb"/>
<Adress Name="aaaa" />
</User>
</Users>
Run Code Online (Sandbox Code Playgroud)
我想User按升序对元素的节点进行排序.我该如何订购Adress元素?
谢谢您的帮助.
LINQPad非常棒,特别有用的是Dump()扩展方法,它可以将几乎任何类型的对象和结构(匿名或非匿名)呈现给控制台.
最初,当我转移到Visual Studio 2010时,我尝试Dump使用委托制作我自己的方法来获取为匿名类型等呈现的值.尽管它变得非常复杂,虽然它起初很有趣和教育,但我需要一个扎实的实施.检查了.NET Reflector中的LINQPad代码后,我更加确信我不会得到正确的实现.
我可以提供免费的库以提供Dump功能吗?
每当我在Visual Studio中键入aspx/ascx页面的标记时,弹出错误列表窗口(当然是空白).有没有办法阻止这种情况发生?
谢谢!
我想要一个像素的分割线,只是为了看起来.我想我可以使用高度为1px的视图来实现这个目标.但是,我在不同的设备上得到了一些非常奇怪的行为 - 有时1px最终为2px.
以此示例布局为例:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<View android:layout_width="fill_parent" android:layout_height="1px"
android:background="@android:color/white" android:layout_marginBottom="4dp" />
<View android:layout_width="fill_parent" android:layout_height="1px"
android:background="@android:color/white" android:layout_marginBottom="4dp" />
<View android:layout_width="fill_parent" android:layout_height="1px"
android:background="@android:color/white" android:layout_marginBottom="4dp" />
<View android:layout_width="fill_parent" android:layout_height="1px"
android:background="@android:color/white" android:layout_marginBottom="4dp" />
<View android:layout_width="fill_parent" android:layout_height="1px"
android:background="@android:color/white" android:layout_marginBottom="4dp" />
<View android:layout_width="fill_parent" android:layout_height="1px"
android:background="@android:color/white" android:layout_marginBottom="4dp" />
<View android:layout_width="fill_parent" android:layout_height="1px"
android:background="@android:color/white" android:layout_marginBottom="4dp" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
在我的G1上运行时,这很好.但在Nexus One上,它在1px线和2px线之间交替.
有谁知道这出错了?为什么Android有时会将1px变为2px?
编辑:为了使这个绝对清楚,我不关心特别是解决我的例子; 在任何情况下,我关心的是能够说"这个视图应该是1px高",而不仅仅是这个例子.
我使用下面的代码生成范围内的随机数...
int randomNumberWithinRange(int min,int max)
{
int snowSize = 0;
do
{
snowSize = rand()%max;
}
while( snowSize < min || snowSize > max );
return snowSize;
}
for(int i = 0; i < 10 ; i++)
NSlog("@"%d",\t", randomNumberWithinRange(1,100));
Run Code Online (Sandbox Code Playgroud)
如果我退出应用程序并重新启动,则会生成相同的数字集.如何为每次启动生成不同的随机数集.
在我的应用程序中,我使用UIImagePickerControllerCropRect裁剪图像,但我想减少自动出现的iphone裁剪盒的大小,以便我的图像裁剪到我想要的完美尺寸.我正在使用以下代码:
-(IBAction) getPhoto:(id) sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if((UIButton *) sender == choosePhotoBtn) {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
picker.allowsImageEditing = YES;
} else {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
[self presentModalViewController:picker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
[picker dismissModalViewControllerAnimated:YES];
imageView.image = image;
CGSize size = [imageView.image size];
CGRect cropRect = CGRectMake(0.0, 0.0, size.width, size.height);
NSLog(@"Original image size = (%f, %f)", size.width, size.height);
NSValue *cropRectValue = [editingInfo objectForKey:@"UIImagePickerControllerCropRect"];
cropRect = [cropRectValue CGRectValue]; …Run Code Online (Sandbox Code Playgroud) 我从Windows-1250代码页中的一些dll(它是一些外部数据源的包装)字符串接收,我想将它们正确地插入(作为unicode)到SQL Server数据库中的表.由于数据库中应该保存该数据的特定行是NVarchar类型,我只需要将其在我的C#代码中转换为unicode并将其作为参数传递.一切都很好,但我偶然发现转换步骤.
我尝试了以下但不起作用:
private static String getUnicodeValue(string string2Encode) //
{
Encoding srcEncoding = Encoding.GetEncoding("Windows-1250");
UnicodeEncoding dstEncoding = new UnicodeEncoding();
byte[] srcBytes = srcEncoding.GetBytes(string2Encode);
byte[] dstBytes = dstEncoding.GetBytes(string2Encode);
return dstEncoding.GetString(dstBytes);
}
Run Code Online (Sandbox Code Playgroud)
当我将这个返回的字符串插入表格时,我没有得到正确的字母,如Đ,đ,Č,č,Ć或ć.
请帮忙!:)