如何在颤动中获取手指移动事件,例如“android 中的 recyclerview 字母索引”检查示例图像。
我创建了一个定位字母索引列表视图,但在 DragUpdate 中找不到当前索引。
var alphabet = ["#","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
new Positioned(
top: .0,
left: 1,
bottom: 10,
width: 55,
child: Material(
borderRadius: BorderRadius.circular(15.0),
elevation: 10.0,
child: ListView.builder(
itemCount: alphabet.length,
itemBuilder: (BuildContext context, int index) {
return new GestureDetector(
onVerticalDragUpdate:
(DragUpdateDetails detail) {
setState(() {
_barOffset += detail.delta.dy;
});
print("$detail");
print("Update ${alphabet[index]}");
},
onVerticalDragStart: (DragStartDetails detail) {
print("onVerticalDragStart");
print("Start ${alphabet[index]}");
},
onVerticalDragEnd: (DragEndDetails detail) {
print("onVerticalDragEnd");
print("End ${alphabet[index]}");
},
onTap: () => print(alphabet[index]),
child: new Container(
margin: EdgeInsets.only(
left: …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个函数,它将在传递索引时为我提供字母位置.它会像excel显示它的列一样.A ... Z,AA,AB ....我写了下面的函数来得到Z的结果.它看起来像
static string GetColumnName(int index)
{
const int alphabetsCount = 26;
if (index <= alphabetsCount)
{
int code = (index - 1) + (int)'A';
return char.ConvertFromUtf32(code);
}
return string.Empty;
}
Run Code Online (Sandbox Code Playgroud)
这工作正常,直到'Z'.如果我通过1则返回'A',如果我通过2则返回'B',依此类推.但是,当我将27传递给这个函数时,我无法弄清楚如何获得AA.我想我需要一个递归方法来找到它.
对这个问题的任何输入都会很棒!
编辑
这是Tordek建议的.但他的代码将失败,如52,78等数字.为此添加了解决方法,这是最终的工作代码.
static string GetColumnName(int index)
{
const int alphabetsCount = 26;
if (index > alphabetsCount)
{
int mod = index % alphabetsCount;
int columnIndex = index / alphabetsCount;
// if mod is 0 (clearly divisible) we reached end of one combination. Something like AZ …Run Code Online (Sandbox Code Playgroud) 我已经实现了一个填充了核心数据的表格,现在我正在尝试通过显示侧面字母(以类似联系人的格式)对其进行索引.
在下面的代码中,如果我使用注释行,我只有现有部分的字母.但我想要整个字母表,所以我改变了返回的数组:
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
//return [fetchedResultsController sectionIndexTitles];
indexArray = [NSArray arrayWithObjects: @"{search}", @"A", @"B", @"C", @"D", @"E", @"F", @"G", @"H", @"I", @"J",@"K", @"L", @"M", @"N", @"O", @"P", @"Q", @"R", @"S", @"T", @"U", @"V", @"W", @"X", @"Y", @"Z", @"#", nil];
return indexArray;
}
Run Code Online (Sandbox Code Playgroud)
所有字母都显示在侧面索引上.但是现在我要实现返回所选部分索引的方法,这里我遇到了一些问题:
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
//return [fetchedResultsController sectionForSectionIndexTitle:title atIndex:index];
NSString *correspondingLetter = [indexArray objectAtIndex:index];
NSUInteger correspondingIndex = [[fetchedResultsController sections] indexOfObject:correspondingLetter];
NSLog(@"------index:%i\ncorrespondingLetter: %@\ncorrespondingIndex: %i\n", index,correspondingLetter, correspondingIndex);
return correspondingIndex;
}
Run Code Online (Sandbox Code Playgroud)
使用上面的代码,如果我使用注释行,每次选择没有相应部分的字母时都会出错.所以我想要做的是使用已选择的字母检索部分索引并将其位置搜索到现有部分.但它不起作用.你有什么想法?
谢谢,yassa
所以我需要一个函数来生成一个从a增加的字母列表,并以zzz结尾.
应该是这样的:
a
b
c
...
aa
ab
ac
...
zzx
zzy
zzz
Run Code Online (Sandbox Code Playgroud)
我目前的代码是这样的:
for combo in product(ascii_lowercase, repeat=3):
print(''.join(combo))
Run Code Online (Sandbox Code Playgroud)
但是,这只会增加3个字母,输出更像
a
ab
abc
abcd
...
Run Code Online (Sandbox Code Playgroud)
因此,回顾:字母增加的函数,当它超过z时,它返回到aa.谢谢!
更新:
我有与以前相同的输出.这是我想要插入的内容:
a = hashlib.md5()
for chars in chain(ALC, product(ALC, repeat=1), product(ALC, repeat=1)):
a.update(chars.encode('utf-8'))
print(''.join(chars))
print(a.hexdigest())
Run Code Online (Sandbox Code Playgroud)
我的哈希最终结果如下:
f1784031a03a8f5b11ead16ab90cc18e
Run Code Online (Sandbox Code Playgroud)
但我希望:
415290769594460e2e485922904f345d
Run Code Online (Sandbox Code Playgroud)
谢谢!
我需要知道文本中第n个字符的字母位置,我读了这个问题的答案,但它不适用于我的Python 3.4
我的节目
# -*- coding: utf-8 -*-
"""
Created on Fri Apr 22 12:24:15 2016
@author: Asus
"""
import string
message='bonjour'
string.lowercase.index('message[2]')
Run Code Online (Sandbox Code Playgroud)
它不适用于ascii_lowercase而不是小写.
错误消息
runfile('C:/Users/Asus/Desktop/Perso/WinPython-64bit-3.4.3.4/python-3.4.3.amd64/Scripts/ESSAI.py',wdir ='C:/ Users/Asus/Desktop/Perso /WinPython-64bit-3.4.3.4/python-3.4.3.amd64/Scripts')Traceback(最近一次调用最后一次):
文件"",第1行,在runfile中('C:/Users/Asus/Desktop/Perso/WinPython-64bit-3.4.3.4/python-3.4.3.amd64/Scripts/ESSAI.py',wdir ='C: /Users/Asus/Desktop/Perso/WinPython-64bit-3.4.3.4/python-3.4.3.amd64/Scripts')
文件"C:\ Users\Asus\Desktop\Perso\WinPython-64bit-3.4.3.4\python-3.4.3.amd64\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py",第685行,in runfile execfile(文件名,命名空间)
文件"C:\ Users\Asus\Desktop\Perso\WinPython-64bit-3.4.3.4\python-3.4.3.amd64\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py",第85行, execfile exec(compile(open(filename,'rb').read(),filename,'exec'),namespace
在string.lowercase.index('message 2 ')中输入文件"C:/Users/Asus/Desktop/Perso/WinPython-64bit-3.4.3.4/python-3.4.3.amd64/Scripts/ESSAI.py",第11行)
AttributeError:'module'对象没有属性'lowercase'
这是我到目前为止:
alphabet = "a" or "b" or "c" or "d" or "e" or "f" or \
"g" or "h" or "i" or "j" or "k" or "l" or \
"m" or "n" or "o" or "p" or "q" or "r" or \
"s" or "t" or "u" or "v" or "w" or "x" or \
"y" or "z"
letter_word_3 = any(alphabet + alphabet + alphabet)
print("Testing: ice")
if "ice" == letter_word_3:
print("Worked!")
else:
print("Didn't work")
print(letter_word_3) # just to see …Run Code Online (Sandbox Code Playgroud) 我不太确定如何表达它,但我正在寻找不仅仅是一个视觉拉丁字母的 unicode 字母。
\n\n到目前为止我在Word中发现了这个:
\n\n还有其他人吗?
\n所以我最近一直在使用.replace()函数,并希望无论用户输入什么都能使其反转.(Aka a - > z,A - > Z,b - > y,B - > Y,......)
我正在使用函数堆栈,所以我只是为每个字母添加了.replace().replace()...但当然这不会起作用,因为每当它命中n时,它将开始反转所有进度而我最终导致翻译不准确.知道如何解决这个问题,因为据我所知,JS没有像Python这样的.reverse()函数吗?
万一你需要它,这是我的代码
//replacing letters
lettertext = ttext.replace("a", "z")
.replace("A", "Z")
.replace("b", "y")
.replace("B", "y")
.replace("c", "x")
.replace("C", "X")
.replace("d", "w")
.replace("D", "W")
.replace("e", "v")
.replace("E", "V")
.replace("f", "u")
.replace("F", "U")
.replace("g", "t")
.replace("G", "T")
.replace("h", "s")
.replace("H", "S")
.replace("i", "r")
.replace("I", "R")
.replace("j", "q")
.replace("J", "Q")
.replace("k", "p")
.replace("K", "P")
.replace("l", "o")
.replace("L", "O")
.replace("m", "n")
.replace("M", "N")
.replace("n", "m")
.replace("N", "M")
.replace("o", "l")
.replace("O", "L") …Run Code Online (Sandbox Code Playgroud) 我几乎遇到了同样的问题: 如何制作一个连续的字母列表python(从az然后从aa,ab,ac等)
但是,我正在像 excel 一样在 gui 中做一个列表,垂直标题上应该是字母 ...aa,ab,ac....dg,dh,di... 要做到这一点,我必须声明每个地方在我的清单上的某个字母。产量可能是不可能的。
我的意思是,让我说,我有 100 个单元格,我想用不同的方式命名它们。单元格 1 应为“A”,单元格 2 应为“B”.... 单元格 27 应为“AA”等等。你可能从excel中知道。我可以手动完成,但这会花费很多时间。
好吧,我尝试在下面使用这段代码,但没有成功。我知道某处应该有一个循环,但我不知道在哪里。
from string import ascii_lowercase
import itertools
def iter_all_strings():
for size in itertools.count(1):
for s in itertools.product(ascii_lowercase, repeat=size):
yield "".join(s)
for s in iter_all_strings():
print(s)
if s == 'bb':
break
Run Code Online (Sandbox Code Playgroud)
范围:“for s in iter_all_strings():” 一直在计数直到中断。我会说这里应该是我的单元格迭代循环。没有地方可以这样做。
如何制作一个表单,其中元素根据其首字母自动分为几个部分,并在右侧添加字母跳线以显示以所选字母开头的元素(就像联系人应用程序一样)?
\n我还注意到一件奇怪的事情,我不知道如何重新创建:并非所有字母都显示出来,其中一些显示为“\xe2\x80\xa2”。但是,当您点击它们时,它们无论如何都会带您到相应的字母。我尝试在 ZStack 中使用 ScrollView(.vertical) 并将 .scrollTo(selection) 添加到按钮的操作中,但是 1) 它没有滚动到我想要的选择 2) 当我点击“\xe2 \x80\xa2",就好像我正在点击所有它们,因为它们都做了点击动画 3) 我无法按照我想要的方式划分列表。\n我有这个:
\nimport SwiftUI\n\nstruct ContentView: View {\n\nlet alphabet = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W", "X","Y", "Z"]\nlet values = ["Avalue", "Bvalue", "Cvalue", "Dvalue"]\n\nvar body: some View {\n ScrollViewReader{ scrollviewr in\n ZStack {\n ScrollView(.vertical) {\n VStack {\n ForEach(alphabet, id: \\.self) { letters in\n Button(letters){\n withAnimation {\n scrollviewr.scrollTo(letters)\n }\n }\n }\n }\n }.offset(x: 180, y: 120)\n\n VStack {\n \n ForEach(values, id: \\.self){ vals in\n Text(vals).id(vals)\n }\n }\n }\n }\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n但我想要这样的: …