dongru2019 2012-07-13 19:47
浏览 264
已采纳

PHP:将字符串拆分为字母和数字组件的最佳方法

I have several strings of the format

AA11
AAAAAA1111111
AA1111111

Which is the best (most efficient) way to separate the alphabetic and numeric components of the string?

  • 写回答

5条回答 默认 最新

  • dongwan0574 2012-07-13 19:51
    关注

    If they're all a series of alpha, followed by a series of numeric, with no non-alphameric characters, then sscanf() is probably more efficient than regexp

    $example = 'AAA11111';
    list($alpha,$numeric) = sscanf($example, "%[A-Z]%d");
    
    var_dump($alpha);
    var_dump($numeric);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥30 vmware exsi重置后的密码
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 UE5#if WITH_EDITOR导致打包的功能不可用
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题