我逐行遍历文件,并将每个单词放入一个数组,这是有效的.但它也会拾取空白行并将其作为数组中的项目,如何跳过空行?
示例文件
Line 1
line 2
line 3
line 4
line 5
line 6
Run Code Online (Sandbox Code Playgroud)
我的代码
while read line ; do
myarray[$index]="$line"
index=$(($index+1))
done < $inputfile
Run Code Online (Sandbox Code Playgroud)
可能的伪代码
while read line ; do
if (line != space);then
myarray[$index]="$line"
fi
index=$(($index+1))
done < $inputfile
Run Code Online (Sandbox Code Playgroud) 我正在使用gridvew作为布局来填充我的项目,圆形按钮,但是我在安装大网格时遇到了问题,11 x 11.当我使用更大的屏幕时,它适合但它会停止一半?这是因为我把我的roundbutton.xml中的szie?在我的手机较小的屏幕上,它确实适合并延伸到屏幕末端的末端.我需要适合屏幕,无论大小为11 x 11?
gridview布局
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridView1"
android:numColumns="11"
android:gravity="center"
android:stretchMode="columnWidth"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</GridView>
Run Code Online (Sandbox Code Playgroud)
item.xml
<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="O"
android:id="@+id/grid_item_label"
android:layout_column="1"
android:background = "@drawable/roundedbutton"/>
Run Code Online (Sandbox Code Playgroud)
roundedbutton.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#9F2200"/>
<stroke android:width="2sp" android:color="#fff" />
<size
android:width="5dp"
android:height="5dp"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
activity_main.java
gridView = (GridView) findViewById(R.id.gridView1);
customGridAdapter = new CustomGridViewAdapter(this, R.layout.button_item, gridArray);
gridView.setAdapter(customGridAdapter);
Run Code Online (Sandbox Code Playgroud)
adapter.java
@Override
public View getView(final int position, View convertView, final ViewGroup parent)
{
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Run Code Online (Sandbox Code Playgroud) 我正在尝试解析DNA蛋白文件.我想提取一定数量的信息.我想解析只有当行以"ATOM"开头并且在第四列的末尾有G,A,T,C时才解析.例如,在下面的片段中,DG将被解析,因为它最后有一个G. 然后将该行保存在文件中.我正在使用bash.你会用什么来做这个?grep,find,sed,awk或某种正则表达式?
谢谢你的帮助!
HETATM 103 HG22 MVA A 8 4.999 -1.260 2.090 1.00 0.00 H
HETATM 104 HG23 MVA A 8 5.639 -2.810 2.604 1.00 0.00 H
TER 105 MVA A 8
ATOM 106 O5' DG C 11 -12.710 1.571 -11.945 1.00 0.00 O
ATOM 107 C5' DG C 11 -13.491 2.438 -11.111 1.00 0.00 C
Run Code Online (Sandbox Code Playgroud)
除了原始问题:
计算总数和个别G,A,T,C?将计算的总数输出到文件中,作为总行数,总计G,总计T,总计A,总计C.
不知道我在这里做错了什么.我无法让它运行.
#include "stdafx.h"
#include <iostream>
#include <vector>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int a[] = { 2, 3, 4, 5 };
skipOne(a, 2);
}
void skipOne(int * array, int n)
{
int total = 0;
for (int i = 0; i < sizeof(array); i++)
{
if (i != n)
{
total = + array[i];
}
}
cout << "The total is: " << total << endl;
}
Run Code Online (Sandbox Code Playgroud)
这是我从下面的帮助中得到的.
#include "stdafx.h"
#include <iostream>
#include <vector>
using namespace …Run Code Online (Sandbox Code Playgroud) 我如何正确编码此声明?有没有更好的办法?
byte[] buf = rtm.getMessageData();
if (buf[0] == 'A'|| 'B' || 'C' || 'D' || 'E' || 'F')
Run Code Online (Sandbox Code Playgroud)