GVKun编程网logo

Sql server中内部函数fn_PhysLocFormatter存在解析错误详解(sql的内置函数)

18

本文将为您提供关于Sqlserver中内部函数fn_PhysLocFormatter存在解析错误详解的详细介绍,我们还将为您解释sql的内置函数的相关知识,同时,我们还将为您提供关于Delphi格式化

本文将为您提供关于Sql server中内部函数fn_PhysLocFormatter存在解析错误详解的详细介绍,我们还将为您解释sql的内置函数的相关知识,同时,我们还将为您提供关于Delphi格式化函数Format、FormatDateTime和FormatFloat、Delphi格式化函数Format、FormatDateTime和FormatFloat详解、Display SQL Server Version Information_javascript技巧、Flutter:在TextInputFormatter中使用NumberFormat的实用信息。

本文目录一览:

Sql server中内部函数fn_PhysLocFormatter存在解析错误详解(sql的内置函数)

Sql server中内部函数fn_PhysLocFormatter存在解析错误详解(sql的内置函数)

前言

有网友指出,sql Server 2012中fn_PhysLocFormatter内部函数在解析数据行记录位置时存在错误,见:http://www.itpub.net/thread-1751655-1-1.html,实际测试后发现,一是2008R2中同样存在问题,二是不仅页号解析存在问题,槽号解析也存在同样问题。

下面先查看表NT_SiteInfo的数据行记录位置。

rush:sql;"> select SiteID,%%physloc%%,sys.fn_PhysLocFormatter(%%physloc%%) from NT_SiteInfo

SiteID

%%physloc%%

sys.fn_PhysLocFormatter(%%physloc%%)

1

0xE900000001000000

(1:59648:0)

23

0xE900000001000100

(1:59648:1)

24

0xE900000001000200

(1:59648:2)

</td&gt; <td&gt; <p>......</p> </td&gt; <td&gt; </td&gt; </tr&gt; <tr&gt; <td&gt; <p>149</p> </td&gt; <td&gt; <p>0xE900000001007F00</p> </td&gt; <td&gt; <p>(1:59648:127)</p> </td&gt; </tr&gt; <tr&gt; <td&gt; <p>150</p> </td&gt; <td&gt; <p>0xE900000001008000</p> </td&gt; <td&gt; <p>(1:59648:128)</p> </td&gt; </tr&gt; <tr&gt; <td&gt; <p>151</p> </td&gt; <td&gt; <p>0xE900000001008100</p> </td&gt; <td&gt; <p>(1:59648:33024)</p> </td&gt; </tr&gt; <tr&gt; <td&gt; <p>152</p> </td&gt; <td&gt; <p>0xE900000001008200</p> </td&gt; <td&gt; <p>(1:59648:33280)</p> </td&gt; </tr&gt; <tr&gt; <td&gt; </td&gt; <td&gt; <p>......</p> </td&gt; <td&gt; </td&gt; </tr&gt; <tr&gt; <td&gt; <p>226</p> </td&gt; <td&gt; <p>0xE90000000100CC00</p> </td&gt; <td&gt; <p>(1:59648:52224)</p> </td&gt; </tr&gt; <tr&gt; <td&gt; <p>227</p> </td&gt; <td&gt; <p>0xE90000000100CD00</p> </td&gt; <td&gt; <p>(1:59648:52480)</p> </td&gt; </tr&gt; <tr&gt; <td&gt; <p>228</p> </td&gt; <td&gt; <p>0x4B02000001000000</p> </td&gt; <td&gt; <p>(1:587:0)</p> </td&gt; </tr&gt; <tr&gt; <td&gt; <p>229</p> </td&gt; <td&gt; <p>0x4B02000001000100</p> </td&gt; <td&gt; <p>(1:587:1)</p> </td&gt; </tr&gt; <tr&gt; <td&gt; </td&gt; <td&gt; <p>......</p> </td&gt; <td&gt; </td&gt; </tr&gt; <tr&gt; <td&gt; <p>360</p> </td&gt; <td&gt; <p>0x4B02000001007F00</p> </td&gt; <td&gt; <p>(1:587:127)</p> </td&gt; </tr&gt; <tr&gt; <td&gt; <p>361</p> </td&gt; <td&gt; <p>0x4B02000001008000</p> </td&gt; <td&gt; <p>(1:587:128)</p> </td&gt; </tr&gt; <tr&gt; <td&gt; <p>362</p> </td&gt; <td&gt; <p>0x4B02000001008100</p> </td&gt; <td&gt; <p>(1:587:33024)</p> </td&gt; </tr&gt; <tr&gt; <td&gt; <p>363</p> </td&gt; <td&gt; <p>0x4B02000001008200</p> </td&gt; <td&gt; <p>(1:587:33280)</p> </td&gt; </tr&gt; <tr&gt; <td&gt; </td&gt; <td&gt; <p>......</p> </td&gt; <td&gt; </td&gt; </tr&gt; <tr&gt; <td&gt; <p>422</p> </td&gt; <td&gt; <p>0x4B0200000100BD00</p> </td&gt; <td&gt; <p>(1:587:48384)</p> </td&gt; </tr&gt; <tr&gt; <td&gt; <p>423</p> </td&gt; <td&gt; <p>0x4B0200000100BE00</p> </td&gt; <td&gt; <p>(1:587:48640)</p> </td&gt; </tr&gt; <tr&gt; <td&gt; <p>424</p> </td&gt; <td&gt; <p>0x3C05000001000000</p> </td&gt; <td&gt; <p>(1:1340:0)</p> </td&gt; </tr&gt; <tr&gt; <td&gt; <p>425</p> </td&gt; <td&gt; <p>0x3C05000001000100</p> </td&gt; <td&gt; <p>(1:1340:1)</p> </td&gt; </tr&gt; <tr&gt; <td&gt; </td&gt; <td&gt; <p>......</p> </td&gt; <td&gt; </td&gt; </tr&gt; <tr&gt; <td&gt; <p>552</p> </td&gt; <td&gt; <p>0x3C05000001008000</p> </td&gt; <td&gt; <p>(1:1340:128)</p> </td&gt; </tr&gt; <tr&gt; <td&gt; <p>553</p> </td&gt; <td&gt; <p>0x3C05000001008100</p> </td&gt; <td&gt; <p>(1:1340:33024)</p> </td&gt; </tr&gt; <tr&gt; <td&gt; </td&gt; <td&gt; </td&gt; <td&gt; </td&gt; </tr&gt; <tr&gt; <td&gt; <p>596</p> </td&gt; <td&gt; <p>0x3C0500000100AC00</p> </td&gt; <td&gt; <p>(1:1340:44032)</p> </td&gt; </tr&gt; <tr&gt; <td&gt; <p>597</p> </td&gt; <td&gt; <p>0x9978000001000000</p> </td&gt; <td&gt; <p>(1:39288:0)</p> </td&gt; </tr&gt; <tr&gt; <td&gt; </td&gt; <td&gt; <p>......</p> </td&gt; <td&gt; </td&gt; </tr&gt; <tr&gt; <td&gt; <p>658</p> </td&gt; <td&gt; <p>0x9978000001003D00</p> </td&gt; <td&gt; <p>(1:39288:61)</p> </td&gt; </tr&gt;

下面查看表NT_SiteInfo分配的数据页情况。

rush:sql;"> dbcc ind(wjgk,nt_siteinfo,0)

PagePID

IAMFID

IAMPID

PageType

IndexLevel

NextPagePID

PrevPagePID

238

NULL

NULL

10

NULL

0

0

233

1

238

1

0

587

0

587

1

238

1

0

1340

233

1340

1

238

1

0

30873

587

30873

1

238

1

0

0

1340

Microsoft未公开的伪列%%physloc%%,类型为Binary(8),返回表中记录的RowID,格式是:前4字节表示页号,中间2字节表示文件号,最后2字节表示槽号。

对照上面的实际数据,可以发现sys.fn_PhysLocFormatter在解析记录位置时,既有采用高字节在前的BIG_ENDIAN格式,又有采用低字节在前的LITTLE_ENDIAN格式,造成采用高字节在前的BIG_ENDIAN格式解析的数据错误:

页号解析:


E9000000解析为59648(E900),错误,实际应为233(E9)

4B020000解析为576(24B),正确

3C050000解析为1340(53C),正确

99780000解析为39288(9978),错误,实际应为30873(7899)

槽号解析:


8000解析为128(0080),正确

8100解析为33024(8100),错误,应为129(0081)

下面给出错误原因。

先看下sys.fn_PhysLocFormatter函数的定义:

rush:sql;"> select OBJECT_DEFinitioN(object_id('sys.fn_PhysLocFormatter')) go

-- Name: sys.fn_PhysLocFormatter

-- Description:
-- Formats the output of %%physloc%% virtual column

-- Notes:

create function sys.fn_PhysLocFormatter (@physical_locator binary (8))
returns varchar (128)
as
begin
declare @page_id binary (4)
declare @file_id binary (2)
declare @slot_id binary (2)
-- Page ID is the first four bytes,then 2 bytes of page ID,then 2 bytes of slot

select @page_id = convert (binary (4),reverse (substring (@physical_locator,1,4)))
select @file_id = convert (binary (2),5,2)))
select @slot_id = convert (binary (2),7,2)))
return '(' + cast (cast (@file_id as int) as varchar) + ':'

  • cast (cast (@page_id as int) as varchar) + ':'
  • cast (cast (@slot_id as int) as varchar) + ')'
    end

再看下reverse函数:

rush:plain;"> select reverse('工人') ---- 人工

(1 行受影响)

select reverse('12345工人')

人工54321

(1 行受影响)

select reverse('工12345人')

人54321工

(1 行受影响)

结论:

问题出在reverse函数上。

reverse函数的作用是字符反转,而不是字节反转,当遇到81-FE之间的字节时,被认为是双字节字符而组合在一起参与反转操作,造成了错误。

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对小编的支持。

总结

以上是小编为你收集整理的Sql server中内部函数fn_PhysLocFormatter存在解析错误详解全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

serverserverserver函数大全sqlsql

MsSQL相关文章

如何在运行 SQL Server 的计算机之间移动数据库
本页概要如果您使用的是 SQL Server 2005备份和还原Sp_detach_db 和 Sp_attach_db 存储过程关于排序规则的说明导入和导出数据(在 SQL Server 数据库之间复
IDENTITY列的检查指定表的当前标识值
DBCC CHECKIDENT 检查指定表的当前标识值,如有必要,还对标识值进行更正。 语法 DBCC CHECKIDENT ( &#39;table_name&#39; [ , { NORESEED
SQL Server 字符串函数速查
这里对 SQL Server 字符串函数进行分门别类地列出,便于查阅和记忆,相信大家都在其它方面有高深的编程基础,从字面上来说大家都知道这些函数的意义,就不对这些函数作过多的解释了,主要谈些经验,具体
SQL Server 数据库中查询及删除重复记录的方法
查询及删除重复记录的方法 1、查找表(people)中多余的重复记录,重复记录是根据单个字段(peopleId)来判断select*frompeoplewherepeopleIdin(selectpe
微软发SQL Server 2008第二个CTP预览版,微软新版开发工具VS 2008 beta2功能定案
微软发SQL Server 2008第二个CTP预览版from: http://news.csdn.net/n/20070807/107158.html8月7日消息,微软公司本周发布了SQL Serv
SQL Server PRB:联机丛书中的“孤立用户疑难解答”主题不完整
症状当您将数据库备份恢复到另一台服务器时,可能会遇到孤立用户的问题。SQL Server 联机丛书中的孤立用户疑难解答主题中没有讲述解决此问题的具体步骤。本文介绍了如何解决孤立用户问题。更多信息虽然术
SQL Server Error: No Process is on the Other End of the Pipe
当登录SQL Server 2005时可能碰到错误: &#39;No Process is on the Other End of the Pipe&#39;。解决方法:(1)Open up SQL
如何解决在运行 SQL Server 的服务器之间移动数据库时的权限问题
概要本文描述如何映射标准登录和集成登录来解决在运行 SQL Server 的服务器之间移动数据库时的权限问题。更多信息当您将数据库从一个运行 SQL Server 的服务器移到另一个运行 SQL Se
  • • 如何在运行 SQL Server 的计算机之间移
  • • IDENTITY列的检查指定表的当前标识值
  • • SQL Server 字符串函数速查
  • • SQL Server 数据库中查询及删除重复记录
  • • 微软发SQL Server 2008第二个CTP预览版
  • • SQL Server PRB:联机丛书中的“孤立用
  • • SQL Server Error: No Process is on t
  • • 如何解决在运行 SQL Server 的服务器之
  • • SQL Sever 问题集锦
  • • SQL Server 2005 的各种版本所支持的功
python-3.xpandasswiftarraysspring-boodataframeamazon-websql-serverfirebaseAllazureVBArubyregexasp.net-cogoPowerShellalgorithmruby-on-raloopsgoogle-cloapache-spavisual-stuelasticseadelphi.net-coremultithreagoogle-clofor-loopunity3dasp.net-mvmachine-leperformancmavenscalaauthenticapysparkdjango-modvb.netspring-mvc

Delphi格式化函数Format、FormatDateTime和FormatFloat

Delphi格式化函数Format、FormatDateTime和FormatFloat

总结

以上是小编为你收集整理的Delphi格式化函数Format、FormatDateTime和FormatFloat全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

Delphi格式化函数Format、FormatDateTime和FormatFloat详解

Delphi格式化函数Format、FormatDateTime和FormatFloat详解

1.Format 根据指定所需要的格式,格式化字符串。 原型: function Format(const Format: string const Args: array of const): string 例子:

var 
  s: string; 
begin 
  //指令类型 type 

  s := Format(''最大整数是: %d; 最小整数是: %d'',[MaxInt,Low(Integer)]); 
  //返回: 最大整数是: 2147483647; 最小整数是: -2147483648 
  { 提示: 格式指令必须以 % 开始, 不区分大小写, %d 代表一个整数; 第二个参数是一个变体数组 } 

  s := Format(''最大的无负号整数是: %u'',[High(Cardinal)]); 
  //返回: 最大的无负号整数是: 4294967295 
  { %u表示一个无负号整数 } 

  s := Format(''输入-2的结果是: %u'',[-2]); 
  //返回: 输入-2的结果是: 4294967294 
  { 如果对应 %u 的是个负数, 则返回: 无负号整数最大值 - 这个数的绝对值 + 1 } 

  s := Format(''%s! %s'',[''你好'',''我是万一'']); 
  //返回: 你好! 我是万一 
  { %s 表示字符串 } 

  s := Format(''%f'',[Pi]); 
  //返回: Pi的值是: 3.14 
  { %f 表示浮点数, 保留或凑够两位小数点 } 

  s := Format(''%g'',[01.2345000]); 
  //返回: 1.2345 
  { %g 表示浮点数, 会去掉多余的 0 } 

  s := Format(''%n'',[12345.6789]); 
  //返回: 12,345.68 
  { %n 表示浮点数, 整数部分使用千位分隔符, 保留两位小数点 } 

  s := Format(''%m'',[12345.6789]); 
  //返回: ¥12,345.68 
  { %m 表示浮点数, 加货币记号, 转换结果取决于系统的地域设置 } 

  s := Format(''%e'',[12345.6789]); 
  //返回: 1.23456789000000E+004 
  { %e 用科学计数法表示整数或浮点数 } 

  s := Format(''%p'',[@Self]); 
  //返回: 0012F5BC 
  { %p 表示指针地址, 用十六进制表示 } 

  s := Format(''%x'',[255]); 
  //返回: FF 
  { %x 用十六进制表示一个整数 } 

  //Index 

  s := Format(''%s%s'',['''','''']); 
  s := Format(''%0:s%1:s'',['''','''']); 
  //返回: 万一 
  { 上面两行的结果是一样的, 0: 对应数组中的第一个值; 1: 对应数组中的第二个值 } 

  s := Format(''%1:s%0:s'',['''','''']); 
  //返回: 一万 
  { 翻转了一下顺序 } 

  s := Format(''%1:s%0:s%0:s%1:s'',['''','''']); 
  //返回: 一万万一 
  { 反复使用 } 

  //Width 与对齐方式 

  s := Format(''%d,%8d,%d'',[1,2,3]); 
  //返回: 1,       2,3 
  { 给第二个值指定了8个字符的宽度, 缺少的用空格填充; 如果指定少了则无效 } 

  s := Format(''%d,%-8d,%d'',[1,2,3]); 
  //返回: 1,2       ,3 
  { - 表示左对齐, 默认是右对齐的; - 符号在 Width 前面、Index 后面 } 

  //指定精度 prec 

  s := Format(''%.9f'',[Pi]); 
  //返回: 3.141592654 
  { 指定小数点的位数, 取值范围1-9, 输入0也当1用 } 

  s := Format(''%.5d'',[12]); 
  //返回: 00012 
  { 这是给整数指定位数, 如果小了则无效 } 

  s := Format(''%.3s'',[''Format'']); 
  //返回: For 
  { 给字符串指定位数, 如果大了则无效 } 

  s := Format(''%.3e'',[123.456]); 
  //返回: 1.23E+002 
  { 给科学计数法指定位数 } 

  //指令顺序: 

  { "%" [index ":"] ["-"] [width] ["." prec] type } 

  ShowMessage(s); 
end;

2.FormatDateTime 格式化日期值 原型:

function FormatDateTime(const Format: string DateTime: TDateTime): string 例子:

var 
  s: string; 
begin 
  //FormatDateTime 的参数1是 String 格式指令, 参数2是 TDateTime 类型的时间 

  s := FormatDateTime(''c'', Now); {返回: 2007-12-18 23:56:05} 
  {指令 c 表示用短格式显示日期与时间} 

  s := FormatDateTime(''d'', Now); {返回: 19} 

  s := FormatDateTime(''d'', StrToDateTime(''2008-1-1'')); {返回: 1} 
  {d 表示日期} 

  s := FormatDateTime(''dd'', Now); {返回: 19} 

  s := FormatDateTime(''dd'', StrToDateTime(''2008-1-1'')); {返回: 01} 
  {dd 表示双位日期} 

  s := FormatDateTime(''ddd'', Now); {返回: 星期三} 

  s := FormatDateTime(''dddd'', Now); {返回: 星期三} 
  {ddd 与 dddd 表示星期; 可能对不同的语种会有区别} 

  s := FormatDateTime(''ddddd'', Now); {返回: 2007-12-19} 
  {ddddd 五个 d 表示短格式日期} 

  s := FormatDateTime(''dddddd'', Now); {返回: 2007年12月19日} 
  {dddddd 六个 d 表示长格式日期} 

  s := FormatDateTime(''e'', Now); {返回: 7} 
  {e 表示年, 1位} 

  s := FormatDateTime(''ee'', Now); {返回: 07} 
  {ee 表示年, 2位} 

  s := FormatDateTime(''eee'', Now); {返回: 2007} 

  s := FormatDateTime(''eeee'', Now); {返回: 2007} 
  {eee 与 eeee 返回4位数年} 

  s := FormatDateTime(''m'', Now); {返回: 12} 
  {m 表示月, 1位} 

  s := FormatDateTime(''mm'', StrToDateTime(''2008-1-1'')); {返回: 01} 
  {mm 表示月, 2位} 

  s := FormatDateTime(''mmm'', Now); {返回: 十二月} 

  s := FormatDateTime(''mmmm'', Now); {返回: 十二月} 
  {mmm 与 mmmm 表示长格式月} 

  s := FormatDateTime(''y'', Now); {返回: 07} 

  s := FormatDateTime(''yy'', Now); {返回: 07} 

  s := FormatDateTime(''yyy'', Now); {返回: 2007} 

  s := FormatDateTime(''yyyy'', Now); {返回: 2007} 
  {y yy yyy yyyy 表示年; 和 e 略有不同} 

  s := FormatDateTime(''t'', Now); {返回: 0:21} 

  s := FormatDateTime(''tt'', Now); {返回: 0:22:13} 
  {t tt 表示时间} 

  s := FormatDateTime(''ampm'', Now); {返回:  上午} 

  s := FormatDateTime(''tampm'', Now); {返回: 0:24 上午} 
  {ampm 表示上午、下午} 

  s := FormatDateTime(''h'', StrToDateTime(''2007-12-30 9:58:06'')); {返回: 9} 

  s := FormatDateTime(''hh'', StrToDateTime(''2007-12-30 9:58:06'')); {返回: 09} 
  {h hh 表示时} 

  s := FormatDateTime(''n'', StrToDateTime(''2007-12-30 9:58:06'')); {返回: 58} 

  s := FormatDateTime(''nn'', StrToDateTime(''2007-12-30 9:58:06'')); {返回: 58} 
  {n nn 表示分} 

  s := FormatDateTime(''s'', StrToDateTime(''2007-12-30 9:58:06'')); {返回: 6} 

  s := FormatDateTime(''ss'', StrToDateTime(''2007-12-30 9:58:06'')); {返回: 06} 
  {s ss 表示秒} 

  s := FormatDateTime(''z'', Now); {返回: 24} 

  s := FormatDateTime(''zz'', Now); {返回: 524} 

  s := FormatDateTime(''zzz'', Now); {返回: 524} 
  {z zz zzz 表示毫秒} 

  s := FormatDateTime(''yy/mm/dd'', Now); {返回: 07/12/19} 

  s := FormatDateTime(''yy/mm/dd'', Now); {返回: 07-12-19} 

  s := FormatDateTime(''yy-mm-dd'', Now); {返回: 07-12-19} 

  s := FormatDateTime(''yy*mm*dd'', Now); {返回: 07*12*19} 
  {使用分隔符, - 是默认的, / 是与 - 等效的, 假如我非要用 / 显示呢?} 

  s := FormatDateTime(''yy"/"mm"/"dd'', Now); {返回: 07/12/19} 

  s := FormatDateTime(''"当前时间是: "yyyy-m-d h:n:s:zz'', Now);  
  {返回: 当前时间是: 2007-12-19 0:47:16:576} 
  {混入的字符串要包含在双引号中} 

  ShowMessage(s); 
end;

3.FormatFloat 格式化浮点数 原型:

function FormatFloat(const Format: string Value: Extended): string 例子:

var 
  s: string; 
begin 
  //FormatFloat 的参数1是 String 格式指令, 参数2是实数类型 Extended 

  s := FormatFloat(''###.###'',12.3456); 
  //返回: 12.346 
  s := FormatFloat(''000.000'',12.3456); 
  //返回: 012.346 

  s := FormatFloat(''#.###'',12.3); 
  //返回: 12.3 
  s := FormatFloat(''0.000'',12.3); 
  //返回: 12.300 

  s := FormatFloat(''#,#.#'',1234567); 
  //返回: 1,234,567 
  s := FormatFloat(''0,0.0'',1234567); 
  //返回: 1,234,567.0 

  s := FormatFloat(''0.00E+0'',1234567); 
  //返回: 1.23E+6 
  s := FormatFloat(''0.00E+00'',1234567); 
  //返回: 1.23E+06 

  //在科学计数法中使用 # 好像不合适? 

  ShowMessage(s); 
end;

参看资料:

http://www.cnblogs.com/del/archive/2007/12/18/1005161.html 

http://www.cnblogs.com/del/archive/2007/12/19/1005205.html 

http://www.cnblogs.com/del/archive/2007/12/19/1005212.html 

http://www.cnblogs.com/sonicit/archive/2007/06/04/769882.html

Display SQL Server Version Information_javascript技巧

Display SQL Server Version Information_javascript技巧

Display SQL Server Version Information

Description

Display SQL Server Version Information.

Supported Platforms

SQL Server 2000
 Yes


Script Code

strDBServerName = "."

Set objSQLServer = CreateObject("SQLDMO.SQLServer")
objSQLServer.LoginSecure = True
objSQLServer.Connect strDBServerName

WScript.Echo "SQL Major Version: " & objSQLServer.VersionMajor
WScript.Echo "SQL Minor Version: " & objSQLServer.VersionMinor
WScript.Echo "SQL Version String: " & objSQLServer.VersionString

Flutter:在TextInputFormatter中使用NumberFormat

Flutter:在TextInputFormatter中使用NumberFormat

我试图使用NumberFromatterTextInputFormatter,但是当我尝试使用它,它完全搞砸了!这是我的TextInputFormatter实现代码:

class NumericTextFormatter extends TextInputFormatter {  TextEditingValue formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue) {    if(newValue.text.length > 0) {      int num = int.parse(newValue.text.replaceAll('','', ''''));      final f = new NumberFormat("#,###");      return newValue.copyWith(text: f.format(num));    } else {       return newValue.copyWith(text: '''');    }  }}

因此,当我将此格式化程序添加到TextField并尝试输入1到9时,我希望看到的内容如下:123,456,789

但这显示在TextField

1121231,23412,354 <- this is where it starts123,5641,235,67412,356,874 <- and it happends again

似乎在添加一个字符后光标移动了。那么有人可以帮我吗?

答案1

小编典典

这是因为在格式化值之后,您要添加一个新字符,但文本选择保持在同一位置,少一个字符,这会导致预期的行为

您可以TextInputFormatter这样修改:

固定以支持所有语言环境并记住光标位置

class NumericTextFormatter extends TextInputFormatter {  TextEditingValue formatEditUpdate(    TextEditingValue oldValue, TextEditingValue newValue) {    if (newValue.text.length == 0) {      return newValue.copyWith(text: '''');    } else if (newValue.text.compareTo(oldValue.text) != 0) {      int selectionIndexFromTheRight = newValue.text.length - newValue.selection.end;      final f = new NumberFormat("#,###");      int num = int.parse(newValue.text.replaceAll(f.symbols.GROUP_SEP, ''''));      final newString = f.format(num);      return new TextEditingValue(        text: newString,        selection: TextSelection.collapsed(offset: newString.length - selectionIndexFromTheRight),      );    } else {      return newValue;    }  }}

今天的关于Sql server中内部函数fn_PhysLocFormatter存在解析错误详解sql的内置函数的分享已经结束,谢谢您的关注,如果想了解更多关于Delphi格式化函数Format、FormatDateTime和FormatFloat、Delphi格式化函数Format、FormatDateTime和FormatFloat详解、Display SQL Server Version Information_javascript技巧、Flutter:在TextInputFormatter中使用NumberFormat的相关知识,请在本站进行查询。

本文标签:

上一篇SqlServer批量备份多个数据库且删除3天前的备份(sql删除备份文件)

下一篇osx – 我可以使用Delphi XE2(v16)轻松编译我现有的适用于Mac OS X的Delphi应用程序?